5
Most read
6
Most read
14
Most read
Department of Computer Science and Engineering
Name of the Faculty : Ms. Aruna T N
Subject Name & Code : CS3492/ Database Management Systems
Branch & Department : Computer Science and Engineering
Year & Semester : II / IV
CS3492/DBMS/IICSE/IVSEM/KG-KiTE
KGiSL Institute of Technology
(Approved by AICTE, New Delhi; Affiliated to Anna University, Chennai)
Recognized by UGC, Accredited by NBA (IT)
365, KGiSL Campus, Thudiyalur Road, Saravanampatti, Coimbatore – 641035.
Course Outcome
CO 1 Demonstrate fundamentals of Data models and Relational
databases - K3 LEVEL
CS3492/DBMS/IICSE/IVSEM/KG-KiTE
Syllabus
UNIT I - RELATIONAL DATABASES
Purpose of Database System – Views of data – Data Models –
Database System Architecture – Introduction to relational databases
– Relational Model – Keys – Relational Algebra – SQL
fundamentals – Advanced SQL features – Embedded SQL–
Dynamic SQL
CS3492/DBMS/IICSE/IVSEM/KG-KiTE
TOPIC
Embedded SQL
CS3492/DBMS/IICSE/IVSEM/KG-KiTE
Embedded SQL
• The Programming module in which the SQL statements are embedded is
called Embedded SQL module.
• It is possible to embed SQL statements inside a variety of programming
languages such as C, C++, Java, Fortran, and PL/1,
• A language to which SQL queries are embedded is referred to as a host
language.
• EXEC SQL statement is used in the host language to identify embedded SQL
request to the preprocessor
EXEC SQL <embedded SQL statement >;
CS3492/DBMS/IICSE/IVSEM/KG-KiTE
Embedded SQL(Cont.)
• Before executing any SQL statements, the program must first connect
to the database. This is done using:
EXEC-SQL connect to server user user-name using password;
Here, server identifies the server to which a connection is to be
established.
• Variables of the host language can be used within embedded SQL
statements. They are preceded by a colon (:) to distinguish from SQL
variables (e.g., :credit_amount )
• In some languages, like COBOL, the semicolon is replaced with END-
EXEC
• In Java embedding uses # SQL { …. };
CS3492/DBMS/IICSE/IVSEM/KG-KiTE
Embedded SQL(Cont.)
• Variables used must be declared within DECLARE section, as illustrated below.
The syntax for declaring the variables, however, follows the usual host language
syntax.
EXEC-SQL BEGIN DECLARE SECTION;
int credit-amount ;
EXEC-SQL END DECLARE SECTION;
CS3492/DBMS/IICSE/IVSEM/KG-KiTE
Embedded SQL(Cont.)
• To write an embedded SQL query, we use the
declare c cursor for <SQL query>
statement. The variable c is used to identify the query
• Example:
From within a host language, find the ID and name of students who
have completed more than the number of credits stored in variable
credit_amount in the host langue.
CS3492/DBMS/IICSE/IVSEM/KG-KiTE
Embedded SQL(Cont.)
CS3492/DBMS/IICSE/IVSEM/KG-KiTE
• Specify the query in SQL as follows:
EXEC SQL
declare c cursor for
select ID, name
from student
where tot_cred > :credit_amount
END_EXEC
Embedded SQL(Cont.)
• The open statement for our example is as follows:
EXEC SQL open c ;
• This statement causes the database system to execute the query and to save the
results within a temporary relation. The query uses the value of the host-
language variable credit-amount at the time the open statement is executed.
• The fetch statement causes the values of one tuple in the query result to be
placed on host language variables.
EXEC SQL fetch c into :si, :sn END_EXEC
CS3492/DBMS/IICSE/IVSEM/KG-KiTE
Embedded SQL(Cont.)
CS3492/DBMS/IICSE/IVSEM/KG-KiTE
• A variable called SQLSTATE in the SQL communication area (SQLCA)
gets set to '02000' to indicate no more data is available
• The close statement causes the database system to delete the temporary
relation that holds the result of the query.
EXEC SQL close c ;
Note: above details vary with language. For example, the Java
embedding defines Java iterators to step through result tuples.
Updates through Embedded SQL
• Embedded SQL expressions for database modification (update, insert, and delete)
• Can update tuples fetched by cursor by declaring that the cursor is for update
EXEC SQL
declare c cursor for
select *
from instructor
where dept_name = 'Music'
for update
CS3492/DBMS/IICSE/IVSEM/KG-KiTE
Updates through Embedded SQL
• We then iterate through the tuples by performing fetch operations on the cursor
(as illustrated earlier), and after fetching each tuple we execute the following
code:
update instructor
set salary = salary + 1000
where current of c
Dynamic SQL
• The dynamic SQL component of SQL allows programs to construct and submit
SQL queries at run time.
• In contrast, embedded SQL statements must be completely present at compile
time, they are compiled by the embedded SQL preprocessor.
• Using dynamic SQL programs can create SQL queries as strings at runtime and
can either have them executed immediately or have them prepared for sub sequent
use.

More Related Content

PPT
Nested Queries-SQL.ppt
PPTX
Sql subquery
PPTX
Data Manipulation Language
PPT
12. Indexing and Hashing in DBMS
PPT
Relational algebra operations
PDF
Relational algebra in dbms
PPT
Object Oriented Design
Nested Queries-SQL.ppt
Sql subquery
Data Manipulation Language
12. Indexing and Hashing in DBMS
Relational algebra operations
Relational algebra in dbms
Object Oriented Design

What's hot (20)

PPTX
SQL, Embedded SQL, Dynamic SQL and SQLJ
PPTX
Common language runtime clr
PPTX
Relational database
PDF
Exception Handling
PPTX
basic structure of SQL FINAL.pptx
PPTX
Triggers
PPT
PL/SQL Introduction and Concepts
PPT
ADO .Net
PPTX
Decomposition using Functional Dependency
PPSX
Functional dependency
PPTX
Internetworking
PDF
Triggers and active database
PPTX
The Relational Database Model
PPTX
SQL Joins.pptx
PPTX
Chapter-4 Enhanced ER Model
PPTX
Normalization in RDBMS
PPT
Unit I Advanced Java Programming Course
PPTX
Reference models in Networks: OSI & TCP/IP
PPTX
Language and Processors for Requirements Specification
SQL, Embedded SQL, Dynamic SQL and SQLJ
Common language runtime clr
Relational database
Exception Handling
basic structure of SQL FINAL.pptx
Triggers
PL/SQL Introduction and Concepts
ADO .Net
Decomposition using Functional Dependency
Functional dependency
Internetworking
Triggers and active database
The Relational Database Model
SQL Joins.pptx
Chapter-4 Enhanced ER Model
Normalization in RDBMS
Unit I Advanced Java Programming Course
Reference models in Networks: OSI & TCP/IP
Language and Processors for Requirements Specification
Ad

Similar to LM7_ Embedded Sql and Dynamic SQL in dbms (20)

PPTX
introduction to SQL query language beginner.ppt
PPTX
Ch as pbdasdadssadsadsadasdasdasdas fdt .pptx
PPTX
embedded-static-&dynamic
PPTX
Unit4_DBMS.pptx
PPT
PPTX
Dynamic and Embedded SQL for db practices.pptx
PPTX
SQL commands in database managemant systems
PDF
Deep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
PPT
DS41_DS305_M05_Transform DS41_DS305_M05_Transform
PPTX
I 3BSC CS C.pptxgggggggggggggggggggggggg
PPT
3.1- Data Management & Retrieval using data analytics techniques
PPTX
PL_SQL, Trigger, Cursor, Stored procedure ,function
PDF
plsql notes.pdf for students Oracle databases
PPTX
CSE311_IAH_Slide06_SQL _Retrival_Queries.pptx
PPT
02 Writing Executable Statments
PPT
Dbms ii mca-ch7-sql-2013
PPTX
Tackle Containerization Advisor (TCA) for Legacy Applications
PPTX
Introduction to SQL, SQL*Plus
PPT
Cursores.ppt
PDF
PROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdf
introduction to SQL query language beginner.ppt
Ch as pbdasdadssadsadsadasdasdasdas fdt .pptx
embedded-static-&dynamic
Unit4_DBMS.pptx
Dynamic and Embedded SQL for db practices.pptx
SQL commands in database managemant systems
Deep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
DS41_DS305_M05_Transform DS41_DS305_M05_Transform
I 3BSC CS C.pptxgggggggggggggggggggggggg
3.1- Data Management & Retrieval using data analytics techniques
PL_SQL, Trigger, Cursor, Stored procedure ,function
plsql notes.pdf for students Oracle databases
CSE311_IAH_Slide06_SQL _Retrival_Queries.pptx
02 Writing Executable Statments
Dbms ii mca-ch7-sql-2013
Tackle Containerization Advisor (TCA) for Legacy Applications
Introduction to SQL, SQL*Plus
Cursores.ppt
PROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdf
Ad

Recently uploaded (20)

PDF
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PPTX
Chapter 2 -Technology and Enginerring Materials + Composites.pptx
PPTX
Amdahl’s law is explained in the above power point presentations
PPTX
mechattonicsand iotwith sensor and actuator
PDF
LOW POWER CLASS AB SI POWER AMPLIFIER FOR WIRELESS MEDICAL SENSOR NETWORK
PDF
20250617 - IR - Global Guide for HR - 51 pages.pdf
DOC
T Pandian CV Madurai pandi kokkaf illaya
PPTX
Software Engineering and software moduleing
PPTX
CONTRACTS IN CONSTRUCTION PROJECTS: TYPES
PPTX
CN_Unite_1 AI&DS ENGGERING SPPU PUNE UNIVERSITY
PDF
Present and Future of Systems Engineering: Air Combat Systems
PPTX
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
PDF
Beginners-Guide-to-Artificial-Intelligence.pdf
PDF
VSL-Strand-Post-tensioning-Systems-Technical-Catalogue_2019-01.pdf
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
Cryptography and Network Security-Module-I.pdf
PPTX
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
PPTX
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
PPTX
PRASUNET_20240614003_231416_0000[1].pptx
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
Exploratory_Data_Analysis_Fundamentals.pdf
Chapter 2 -Technology and Enginerring Materials + Composites.pptx
Amdahl’s law is explained in the above power point presentations
mechattonicsand iotwith sensor and actuator
LOW POWER CLASS AB SI POWER AMPLIFIER FOR WIRELESS MEDICAL SENSOR NETWORK
20250617 - IR - Global Guide for HR - 51 pages.pdf
T Pandian CV Madurai pandi kokkaf illaya
Software Engineering and software moduleing
CONTRACTS IN CONSTRUCTION PROJECTS: TYPES
CN_Unite_1 AI&DS ENGGERING SPPU PUNE UNIVERSITY
Present and Future of Systems Engineering: Air Combat Systems
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
Beginners-Guide-to-Artificial-Intelligence.pdf
VSL-Strand-Post-tensioning-Systems-Technical-Catalogue_2019-01.pdf
Management Information system : MIS-e-Business Systems.pptx
Cryptography and Network Security-Module-I.pdf
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
PRASUNET_20240614003_231416_0000[1].pptx

LM7_ Embedded Sql and Dynamic SQL in dbms

  • 1. Department of Computer Science and Engineering Name of the Faculty : Ms. Aruna T N Subject Name & Code : CS3492/ Database Management Systems Branch & Department : Computer Science and Engineering Year & Semester : II / IV CS3492/DBMS/IICSE/IVSEM/KG-KiTE KGiSL Institute of Technology (Approved by AICTE, New Delhi; Affiliated to Anna University, Chennai) Recognized by UGC, Accredited by NBA (IT) 365, KGiSL Campus, Thudiyalur Road, Saravanampatti, Coimbatore – 641035.
  • 2. Course Outcome CO 1 Demonstrate fundamentals of Data models and Relational databases - K3 LEVEL CS3492/DBMS/IICSE/IVSEM/KG-KiTE
  • 3. Syllabus UNIT I - RELATIONAL DATABASES Purpose of Database System – Views of data – Data Models – Database System Architecture – Introduction to relational databases – Relational Model – Keys – Relational Algebra – SQL fundamentals – Advanced SQL features – Embedded SQL– Dynamic SQL CS3492/DBMS/IICSE/IVSEM/KG-KiTE
  • 5. Embedded SQL • The Programming module in which the SQL statements are embedded is called Embedded SQL module. • It is possible to embed SQL statements inside a variety of programming languages such as C, C++, Java, Fortran, and PL/1, • A language to which SQL queries are embedded is referred to as a host language. • EXEC SQL statement is used in the host language to identify embedded SQL request to the preprocessor EXEC SQL <embedded SQL statement >; CS3492/DBMS/IICSE/IVSEM/KG-KiTE
  • 6. Embedded SQL(Cont.) • Before executing any SQL statements, the program must first connect to the database. This is done using: EXEC-SQL connect to server user user-name using password; Here, server identifies the server to which a connection is to be established. • Variables of the host language can be used within embedded SQL statements. They are preceded by a colon (:) to distinguish from SQL variables (e.g., :credit_amount ) • In some languages, like COBOL, the semicolon is replaced with END- EXEC • In Java embedding uses # SQL { …. }; CS3492/DBMS/IICSE/IVSEM/KG-KiTE
  • 7. Embedded SQL(Cont.) • Variables used must be declared within DECLARE section, as illustrated below. The syntax for declaring the variables, however, follows the usual host language syntax. EXEC-SQL BEGIN DECLARE SECTION; int credit-amount ; EXEC-SQL END DECLARE SECTION; CS3492/DBMS/IICSE/IVSEM/KG-KiTE
  • 8. Embedded SQL(Cont.) • To write an embedded SQL query, we use the declare c cursor for <SQL query> statement. The variable c is used to identify the query • Example: From within a host language, find the ID and name of students who have completed more than the number of credits stored in variable credit_amount in the host langue. CS3492/DBMS/IICSE/IVSEM/KG-KiTE
  • 9. Embedded SQL(Cont.) CS3492/DBMS/IICSE/IVSEM/KG-KiTE • Specify the query in SQL as follows: EXEC SQL declare c cursor for select ID, name from student where tot_cred > :credit_amount END_EXEC
  • 10. Embedded SQL(Cont.) • The open statement for our example is as follows: EXEC SQL open c ; • This statement causes the database system to execute the query and to save the results within a temporary relation. The query uses the value of the host- language variable credit-amount at the time the open statement is executed. • The fetch statement causes the values of one tuple in the query result to be placed on host language variables. EXEC SQL fetch c into :si, :sn END_EXEC CS3492/DBMS/IICSE/IVSEM/KG-KiTE
  • 11. Embedded SQL(Cont.) CS3492/DBMS/IICSE/IVSEM/KG-KiTE • A variable called SQLSTATE in the SQL communication area (SQLCA) gets set to '02000' to indicate no more data is available • The close statement causes the database system to delete the temporary relation that holds the result of the query. EXEC SQL close c ; Note: above details vary with language. For example, the Java embedding defines Java iterators to step through result tuples.
  • 12. Updates through Embedded SQL • Embedded SQL expressions for database modification (update, insert, and delete) • Can update tuples fetched by cursor by declaring that the cursor is for update EXEC SQL declare c cursor for select * from instructor where dept_name = 'Music' for update CS3492/DBMS/IICSE/IVSEM/KG-KiTE
  • 13. Updates through Embedded SQL • We then iterate through the tuples by performing fetch operations on the cursor (as illustrated earlier), and after fetching each tuple we execute the following code: update instructor set salary = salary + 1000 where current of c
  • 14. Dynamic SQL • The dynamic SQL component of SQL allows programs to construct and submit SQL queries at run time. • In contrast, embedded SQL statements must be completely present at compile time, they are compiled by the embedded SQL preprocessor. • Using dynamic SQL programs can create SQL queries as strings at runtime and can either have them executed immediately or have them prepared for sub sequent use.