SlideShare a Scribd company logo
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
Most read
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
Most read
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.
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)

Distributed DBMS - Unit 1 - Introduction
Distributed DBMS - Unit 1 - IntroductionDistributed DBMS - Unit 1 - Introduction
Distributed DBMS - Unit 1 - Introduction
Gyanmanjari Institute Of Technology
 
Naming in Distributed Systems
Naming in Distributed SystemsNaming in Distributed Systems
Naming in Distributed Systems
Nandakumar P
 
2 PHASE COMMIT PROTOCOL
2 PHASE COMMIT PROTOCOL2 PHASE COMMIT PROTOCOL
2 PHASE COMMIT PROTOCOL
KABILESH RAMAR
 
Query processing strategies in distributed database
Query processing strategies in distributed databaseQuery processing strategies in distributed database
Query processing strategies in distributed database
ShreerajKhatiwada
 
Parallel Database
Parallel DatabaseParallel Database
Parallel Database
VESIT/University of Mumbai
 
Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.
Meghaj Mallick
 
Ordbms
OrdbmsOrdbms
Ordbms
ramandeep brar
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMS
Megha Patel
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
Dharita Chokshi
 
Coupling and cohesion
Coupling and cohesionCoupling and cohesion
Coupling and cohesion
Sutha31
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler design
Rajkumar R
 
Distributed Operating System_4
Distributed Operating System_4Distributed Operating System_4
Distributed Operating System_4
Dr Sandeep Kumar Poonia
 
Transaction Properties in database | ACID Properties
Transaction Properties in database | ACID PropertiesTransaction Properties in database | ACID Properties
Transaction Properties in database | ACID Properties
nomanbarki
 
Issues in Data Link Layer
Issues in Data Link LayerIssues in Data Link Layer
Issues in Data Link Layer
selvakumar_b1985
 
Introduction to System Calls
Introduction to System CallsIntroduction to System Calls
Introduction to System Calls
Vandana Salve
 
Acid properties
Acid propertiesAcid properties
Acid properties
Abhilasha Lahigude
 
Finite automata
Finite automataFinite automata
Finite automata
Bipul Roy Bpl
 
Database management functions
Database management functionsDatabase management functions
Database management functions
yhen06
 
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFDatabase Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Oum Saokosal
 
Distributed database management system
Distributed database management  systemDistributed database management  system
Distributed database management system
Pooja Dixit
 
Naming in Distributed Systems
Naming in Distributed SystemsNaming in Distributed Systems
Naming in Distributed Systems
Nandakumar P
 
2 PHASE COMMIT PROTOCOL
2 PHASE COMMIT PROTOCOL2 PHASE COMMIT PROTOCOL
2 PHASE COMMIT PROTOCOL
KABILESH RAMAR
 
Query processing strategies in distributed database
Query processing strategies in distributed databaseQuery processing strategies in distributed database
Query processing strategies in distributed database
ShreerajKhatiwada
 
Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.
Meghaj Mallick
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMS
Megha Patel
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
Dharita Chokshi
 
Coupling and cohesion
Coupling and cohesionCoupling and cohesion
Coupling and cohesion
Sutha31
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler design
Rajkumar R
 
Transaction Properties in database | ACID Properties
Transaction Properties in database | ACID PropertiesTransaction Properties in database | ACID Properties
Transaction Properties in database | ACID Properties
nomanbarki
 
Introduction to System Calls
Introduction to System CallsIntroduction to System Calls
Introduction to System Calls
Vandana Salve
 
Database management functions
Database management functionsDatabase management functions
Database management functions
yhen06
 
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFDatabase Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Oum Saokosal
 
Distributed database management system
Distributed database management  systemDistributed database management  system
Distributed database management system
Pooja Dixit
 

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

Dynamic and Embedded SQL for db practices.pptx
Dynamic and Embedded SQL for db practices.pptxDynamic and Embedded SQL for db practices.pptx
Dynamic and Embedded SQL for db practices.pptx
angelinjeba6
 
Chapter09
Chapter09Chapter09
Chapter09
sasa_eldoby
 
embedded-static-&dynamic
embedded-static-&dynamicembedded-static-&dynamic
embedded-static-&dynamic
Saranya Natarajan
 
Slides11
Slides11Slides11
Slides11
jayalo
 
[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07
AnusAhmad
 
Ddl
DdlDdl
Ddl
Welly Dian Astika
 
DBMS MOD 3_Chap2.pptx
DBMS MOD 3_Chap2.pptxDBMS MOD 3_Chap2.pptx
DBMS MOD 3_Chap2.pptx
SRAHUL23
 
Dbms & prog lang
Dbms & prog langDbms & prog lang
Dbms & prog lang
Tech_MX
 
as
asas
as
guest8b06a3
 
Pl sql content
Pl sql contentPl sql content
Pl sql content
MargaretMaryT
 
Advanced SQL - Database Access from Programming Languages
Advanced SQL - Database Access  from Programming LanguagesAdvanced SQL - Database Access  from Programming Languages
Advanced SQL - Database Access from Programming Languages
S.Shayan Daneshvar
 
Dynamic SQL (STRUCTURED QUERY LANGUAGE)
Dynamic SQL  (STRUCTURED QUERY LANGUAGE)Dynamic SQL  (STRUCTURED QUERY LANGUAGE)
Dynamic SQL (STRUCTURED QUERY LANGUAGE)
cspratheekshaa29
 
Introduction to Structured Query Language
Introduction to Structured Query LanguageIntroduction to Structured Query Language
Introduction to Structured Query Language
agrawalmonikacomp
 
Database Systems - Introduction to SQL (Chapter 3/1)
Database Systems - Introduction to SQL (Chapter 3/1)Database Systems - Introduction to SQL (Chapter 3/1)
Database Systems - Introduction to SQL (Chapter 3/1)
Vidyasagar Mundroy
 
DBMS languages/ Types of SQL Commands
DBMS languages/ Types of SQL CommandsDBMS languages/ Types of SQL Commands
DBMS languages/ Types of SQL Commands
BHARATH KUMAR
 
Ibm db2 10.5 for linux, unix, and windows developing embedded sql applications
Ibm db2 10.5 for linux, unix, and windows   developing embedded sql applicationsIbm db2 10.5 for linux, unix, and windows   developing embedded sql applications
Ibm db2 10.5 for linux, unix, and windows developing embedded sql applications
bupbechanhgmail
 
Lecture 2 DATABASE LANGUAGE.pptx
Lecture 2 DATABASE LANGUAGE.pptxLecture 2 DATABASE LANGUAGE.pptx
Lecture 2 DATABASE LANGUAGE.pptx
sazia7
 
4_59788783hhhhhhhhhhhhhhhhhhhhhhhhhhhhh34715564451.pdf
4_59788783hhhhhhhhhhhhhhhhhhhhhhhhhhhhh34715564451.pdf4_59788783hhhhhhhhhhhhhhhhhhhhhhhhhhhhh34715564451.pdf
4_59788783hhhhhhhhhhhhhhhhhhhhhhhhhhhhh34715564451.pdf
kassyemariyam21
 
Database part2-
Database part2-Database part2-
Database part2-
Taymoor Nazmy
 
MODULE_2_VTU_CSE_BSC403_DATABASE_DBMS_MODULE_3.pptx.pptx
MODULE_2_VTU_CSE_BSC403_DATABASE_DBMS_MODULE_3.pptx.pptxMODULE_2_VTU_CSE_BSC403_DATABASE_DBMS_MODULE_3.pptx.pptx
MODULE_2_VTU_CSE_BSC403_DATABASE_DBMS_MODULE_3.pptx.pptx
AslamNandyal1
 
Dynamic and Embedded SQL for db practices.pptx
Dynamic and Embedded SQL for db practices.pptxDynamic and Embedded SQL for db practices.pptx
Dynamic and Embedded SQL for db practices.pptx
angelinjeba6
 
Slides11
Slides11Slides11
Slides11
jayalo
 
[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07
AnusAhmad
 
DBMS MOD 3_Chap2.pptx
DBMS MOD 3_Chap2.pptxDBMS MOD 3_Chap2.pptx
DBMS MOD 3_Chap2.pptx
SRAHUL23
 
Dbms & prog lang
Dbms & prog langDbms & prog lang
Dbms & prog lang
Tech_MX
 
Advanced SQL - Database Access from Programming Languages
Advanced SQL - Database Access  from Programming LanguagesAdvanced SQL - Database Access  from Programming Languages
Advanced SQL - Database Access from Programming Languages
S.Shayan Daneshvar
 
Dynamic SQL (STRUCTURED QUERY LANGUAGE)
Dynamic SQL  (STRUCTURED QUERY LANGUAGE)Dynamic SQL  (STRUCTURED QUERY LANGUAGE)
Dynamic SQL (STRUCTURED QUERY LANGUAGE)
cspratheekshaa29
 
Introduction to Structured Query Language
Introduction to Structured Query LanguageIntroduction to Structured Query Language
Introduction to Structured Query Language
agrawalmonikacomp
 
Database Systems - Introduction to SQL (Chapter 3/1)
Database Systems - Introduction to SQL (Chapter 3/1)Database Systems - Introduction to SQL (Chapter 3/1)
Database Systems - Introduction to SQL (Chapter 3/1)
Vidyasagar Mundroy
 
DBMS languages/ Types of SQL Commands
DBMS languages/ Types of SQL CommandsDBMS languages/ Types of SQL Commands
DBMS languages/ Types of SQL Commands
BHARATH KUMAR
 
Ibm db2 10.5 for linux, unix, and windows developing embedded sql applications
Ibm db2 10.5 for linux, unix, and windows   developing embedded sql applicationsIbm db2 10.5 for linux, unix, and windows   developing embedded sql applications
Ibm db2 10.5 for linux, unix, and windows developing embedded sql applications
bupbechanhgmail
 
Lecture 2 DATABASE LANGUAGE.pptx
Lecture 2 DATABASE LANGUAGE.pptxLecture 2 DATABASE LANGUAGE.pptx
Lecture 2 DATABASE LANGUAGE.pptx
sazia7
 
4_59788783hhhhhhhhhhhhhhhhhhhhhhhhhhhhh34715564451.pdf
4_59788783hhhhhhhhhhhhhhhhhhhhhhhhhhhhh34715564451.pdf4_59788783hhhhhhhhhhhhhhhhhhhhhhhhhhhhh34715564451.pdf
4_59788783hhhhhhhhhhhhhhhhhhhhhhhhhhhhh34715564451.pdf
kassyemariyam21
 
MODULE_2_VTU_CSE_BSC403_DATABASE_DBMS_MODULE_3.pptx.pptx
MODULE_2_VTU_CSE_BSC403_DATABASE_DBMS_MODULE_3.pptx.pptxMODULE_2_VTU_CSE_BSC403_DATABASE_DBMS_MODULE_3.pptx.pptx
MODULE_2_VTU_CSE_BSC403_DATABASE_DBMS_MODULE_3.pptx.pptx
AslamNandyal1
 
Ad

Recently uploaded (20)

SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair KitSEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401
Unknown
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) ProjectMontreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 
Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)
pelumiadigun2006
 
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
Journal of Soft Computing in Civil Engineering
 
22PCOAM16 _ML_Unit 3 Notes & Question bank
22PCOAM16 _ML_Unit 3 Notes & Question bank22PCOAM16 _ML_Unit 3 Notes & Question bank
22PCOAM16 _ML_Unit 3 Notes & Question bank
Guru Nanak Technical Institutions
 
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbbTree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
RATNANITINPATIL
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Ppt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineeringPpt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineering
ravindrabodke
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptxPrésentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 
IntroSlides-June-GDG-Cloud-Munich community [email protected]
IntroSlides-June-GDG-Cloud-Munich community gathering@Netlight.pdfIntroSlides-June-GDG-Cloud-Munich community gathering@Netlight.pdf
IntroSlides-June-GDG-Cloud-Munich community [email protected]
Luiz Carneiro
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODSWIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
samueljackson3773
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.
Sowndarya6
 
First Review PPT gfinal gyft ftu liu yrfut go
First Review PPT gfinal gyft  ftu liu yrfut goFirst Review PPT gfinal gyft  ftu liu yrfut go
First Review PPT gfinal gyft ftu liu yrfut go
Sowndarya6
 
Computer_vision-photometric_image_formation.pdf
Computer_vision-photometric_image_formation.pdfComputer_vision-photometric_image_formation.pdf
Computer_vision-photometric_image_formation.pdf
kumarprem6767merp
 
Artificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowyArtificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowy
dominikamizerska1
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
djiceramil
 
SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair KitSEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401
Unknown
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) ProjectMontreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 
Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)
pelumiadigun2006
 
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbbTree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
RATNANITINPATIL
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Ppt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineeringPpt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineering
ravindrabodke
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptxPrésentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODSWIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
samueljackson3773
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.
Sowndarya6
 
First Review PPT gfinal gyft ftu liu yrfut go
First Review PPT gfinal gyft  ftu liu yrfut goFirst Review PPT gfinal gyft  ftu liu yrfut go
First Review PPT gfinal gyft ftu liu yrfut go
Sowndarya6
 
Computer_vision-photometric_image_formation.pdf
Computer_vision-photometric_image_formation.pdfComputer_vision-photometric_image_formation.pdf
Computer_vision-photometric_image_formation.pdf
kumarprem6767merp
 
Artificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowyArtificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowy
dominikamizerska1
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
djiceramil
 
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.