Embedded SQL

Embedded SQL

Embedded SQL: SQL provides a powerful declarative query language writing queries in SQL is typically much easier then coding the same queries in a general-purpose programming language. However, access to a database from a general purpose programming language is required for at least two reasons:
  1. Not all queries can be expressed in SQL, since SQL does not provide the full expressive power of a general-purpose programming-language. That is, there exist queries that can be expressed in a language such as Pascal, C, COBOL, or FORTRAN that cannot be expressed in SQL within a more powerful language.
SQL is designed such that queries written in it can be optimized automatically and executed efficiently-and providing the full power of a programming language makes automatic optimization exceedingly difficult.
2. Non declarative actions– such as printing a report, interacting with a user, or sending the results of a query to a graphical user, or sending a result a query to graphical user interface-cannot be done from within SQL. Applications typically have several components, and querying or updating data is only one component; other components are written in general-purpose programming languages. For an integrated application, the programs written in the programming languages. For an integrated application, the programs written in the programming language must be able to access the database.
SQL can be used in conjunction with a general-purpose programming language. The SQL standard defines embedding of SQL in a verity of programming language, such as definition can be embedded in the host language program. The embedded SQL statement is distinguished from programming language statements by prefixing it with a special character or command so that a pre-processor can separate the embedded SQL statements from the host language code.
Programs written in the host language can use the embedded SQL syntax to access and update data stored in a database. This embedded from of SQL extends the programmer’s ability to manipulate the database even further. In embedded SQL, all query processing is performed by the database system. The result of the query is then made available to the program one tuple (record) at a time. An embedded SQL program must be processed by a special processor to compilation. Embedded SQL requests are replaced with host language declarations and procedure calls that allow run-time execution of the database accesses and the resulting program is compiled by the host-language compiler.
To identify embedded SQL requests to the preprocessor, we use the EXEC SQL statement and it has the following from.
EXEC SQL < embedded SQL statement > END-EXEC.
The exact syntax for embedded SQL request depends on the language in which SQL is embedded.

Leave a Reply

Your email address will not be published.