EMBEDDED SQL
Programs written in high level languages such as C/C++ can use EMBEDDED SQL to access and update data stored in a database. Thus embedded SQL helps programmers in manipulating as well as updating a database easily. All queries are sent by the host program to the database management system (DBMS) through embedded SQL. The DBMS software package processes such queries and sends the result to the program, one tuple (record) at a time.
The host program that incorporates embedded SQL within itself, must be processed by a special pre-processor before compilation. The special processor replaces the SQL syntax with the host language syntax and declarations. This allows for the run time execution of database queries. For example Pre*C/C++ is a pre-compiler that converts SQL statements into C statements so that the resulting output file can then be compiled by a C/C++ compiler.
For special processor to distinguish embedded SQL statements from the host language statements, we use EXEC SQL. This is done in the following statement.
EXEC SQL <EMBEDDED SQL STATEMENTS> END EXEC.
WHY EMBEDDED SQL?
SQL is a non procedural language. Although its non procedural character gives many specialties. Inside a host program, SQL will be used to perform the following operations:
Passing values from the host program to the database table.
Operating on database table. passing results outputs to the host program.
In order to embed SQL into another programming language you must use a software package that provides support for the programming language as well as SQL.
OR
Embedded SQL refers to the incorporation of SQL statements in a program written in a procedural programming language such as C, Java, or Python. Embedded SQL allows programmers to access databases using SQL statements within their programs. This eliminates the need for separate programs to interact with the database and streamlines the entire process.
Embedded SQL involves embedding SQL statements in host-language programs. The embedded SQL statements are preprocessed before the program is compiled. The embedded SQL statements are translated into calls to the SQL runtime library. This allows the program to interact with the database.
One advantage of embedded SQL is that it provides a level of abstraction between the host programming language and the database. This allows programmers to use the host language to perform database operations without having to learn a new language. It also allows for more flexibility and control over the interaction with the database.
Another advantage of embedded SQL is that it provides better security for databases. By embedding SQL statements within the program, security can be added by controlling who has access to the program.
Embedded SQL also offers better performance because the database can be accessed directly from the host-language program. This eliminates the need for separate programs to interact with the database and reduces the overhead associated with such programs.
However, embedded SQL also has some disadvantages. One major disadvantage is that it can make the host program more complex, as it requires the programmer to write both SQL and host-language code. This can be challenging for programmers who are not proficient in both languages.
Another disadvantage of embedded SQL is that it can be difficult to maintain the code. Changes to the database schema can require changes to the SQL statements embedded in the program. This can make maintenance more difficult and time-consuming.
In summary, embedded SQL provides a way to access databases using SQL statements within a host-language program. This approach offers several advantages, including better security, better performance, and more flexibility. However, it also has some disadvantages, including increased complexity and maintenance challenges.