SlideShare a Scribd company logo
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

What's hot (20)

PPTX
Data cube computation
Rashmi Sheikh
 
PPTX
Database security
Software Engineering
 
PPTX
Database recovery
Vritti Malhotra
 
PPTX
Security & protection in operating system
Abou Bakr Ashraf
 
PPTX
Dbms architecture
Shubham Dwivedi
 
PPTX
DBMS and its Models
AhmadShah Sultani
 
PPTX
Integrity Constraints
Megha yadav
 
PPT
Lecture 01 introduction to database
emailharmeet
 
PPTX
Data Flow Diagrams
Reetesh Gupta
 
PPTX
Frame class library and namespace
Jaya Kumari
 
PPTX
Concurrency Control in Database Management System
Janki Shah
 
PPTX
Relational model
Dabbal Singh Mahara
 
PPTX
Single source Shortest path algorithm with example
VINITACHAUHAN21
 
PPTX
Log based and Recovery with concurrent transaction
nikunjandy
 
PPS
Oracle Database Overview
honglee71
 
DOCX
Concurrency Control Techniques
Raj vardhan
 
PPT
SQL.ppt
Ranjit273515
 
PPTX
introduction to NOSQL Database
nehabsairam
 
PPTX
Relational Database Design
Archit Saxena
 
Data cube computation
Rashmi Sheikh
 
Database security
Software Engineering
 
Database recovery
Vritti Malhotra
 
Security & protection in operating system
Abou Bakr Ashraf
 
Dbms architecture
Shubham Dwivedi
 
DBMS and its Models
AhmadShah Sultani
 
Integrity Constraints
Megha yadav
 
Lecture 01 introduction to database
emailharmeet
 
Data Flow Diagrams
Reetesh Gupta
 
Frame class library and namespace
Jaya Kumari
 
Concurrency Control in Database Management System
Janki Shah
 
Relational model
Dabbal Singh Mahara
 
Single source Shortest path algorithm with example
VINITACHAUHAN21
 
Log based and Recovery with concurrent transaction
nikunjandy
 
Oracle Database Overview
honglee71
 
Concurrency Control Techniques
Raj vardhan
 
SQL.ppt
Ranjit273515
 
introduction to NOSQL Database
nehabsairam
 
Relational Database Design
Archit Saxena
 

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

PPTX
SQL, Embedded SQL, Dynamic SQL and SQLJ
Dharita Chokshi
 
PPTX
Dynamic and Embedded SQL for db practices.pptx
angelinjeba6
 
PPT
Chapter09
sasa_eldoby
 
PPTX
embedded-static-&dynamic
Saranya Natarajan
 
PPT
Slides11
jayalo
 
PDF
[Www.pkbulk.blogspot.com]dbms07
AnusAhmad
 
PPTX
DBMS MOD 3_Chap2.pptx
SRAHUL23
 
PPT
Dbms & prog lang
Tech_MX
 
PPTX
Pl sql content
MargaretMaryT
 
PDF
Advanced SQL - Database Access from Programming Languages
S.Shayan Daneshvar
 
PPTX
Dynamic SQL (STRUCTURED QUERY LANGUAGE)
cspratheekshaa29
 
PPTX
Introduction to Structured Query Language
agrawalmonikacomp
 
PDF
Database Systems - Introduction to SQL (Chapter 3/1)
Vidyasagar Mundroy
 
PPTX
DBMS languages/ Types of SQL Commands
BHARATH KUMAR
 
PDF
Ibm db2 10.5 for linux, unix, and windows developing embedded sql applications
bupbechanhgmail
 
PPTX
Lecture 2 DATABASE LANGUAGE.pptx
sazia7
 
PDF
4_59788783hhhhhhhhhhhhhhhhhhhhhhhhhhhhh34715564451.pdf
kassyemariyam21
 
PPTX
Database part2-
Taymoor Nazmy
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
Dharita Chokshi
 
Dynamic and Embedded SQL for db practices.pptx
angelinjeba6
 
Chapter09
sasa_eldoby
 
embedded-static-&dynamic
Saranya Natarajan
 
Slides11
jayalo
 
[Www.pkbulk.blogspot.com]dbms07
AnusAhmad
 
DBMS MOD 3_Chap2.pptx
SRAHUL23
 
Dbms & prog lang
Tech_MX
 
Pl sql content
MargaretMaryT
 
Advanced SQL - Database Access from Programming Languages
S.Shayan Daneshvar
 
Dynamic SQL (STRUCTURED QUERY LANGUAGE)
cspratheekshaa29
 
Introduction to Structured Query Language
agrawalmonikacomp
 
Database Systems - Introduction to SQL (Chapter 3/1)
Vidyasagar Mundroy
 
DBMS languages/ Types of SQL Commands
BHARATH KUMAR
 
Ibm db2 10.5 for linux, unix, and windows developing embedded sql applications
bupbechanhgmail
 
Lecture 2 DATABASE LANGUAGE.pptx
sazia7
 
4_59788783hhhhhhhhhhhhhhhhhhhhhhhhhhhhh34715564451.pdf
kassyemariyam21
 
Database part2-
Taymoor Nazmy
 
Ad

Recently uploaded (20)

PDF
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
PDF
NTPC PATRATU Summer internship report.pdf
hemant03701
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PPTX
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
PPTX
仿制LethbridgeOffer加拿大莱斯桥大学毕业证范本,Lethbridge成绩单
Taqyea
 
PPTX
原版一样(EC Lille毕业证书)法国里尔中央理工学院毕业证补办
Taqyea
 
PDF
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
PDF
MODULE-5 notes [BCG402-CG&V] PART-B.pdf
Alvas Institute of Engineering and technology, Moodabidri
 
PPTX
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PDF
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
PDF
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PDF
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
PPTX
Distribution reservoir and service storage pptx
dhanashree78
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PPTX
darshai cross section and river section analysis
muk7971
 
PPTX
Knowledge Representation : Semantic Networks
Amity University, Patna
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
NTPC PATRATU Summer internship report.pdf
hemant03701
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
仿制LethbridgeOffer加拿大莱斯桥大学毕业证范本,Lethbridge成绩单
Taqyea
 
原版一样(EC Lille毕业证书)法国里尔中央理工学院毕业证补办
Taqyea
 
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
MODULE-5 notes [BCG402-CG&V] PART-B.pdf
Alvas Institute of Engineering and technology, Moodabidri
 
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
Distribution reservoir and service storage pptx
dhanashree78
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
darshai cross section and river section analysis
muk7971
 
Knowledge Representation : Semantic Networks
Amity University, Patna
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
Ad

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.