Dynamic SQL and Embedded SQL
SQL (Structured Query Language)
SQL (Structured Query Language) is a programming language used to manage relational databases and perform various operations on the data they contain. SQL is a programming language that is used to conduct operations on database records, such as updating, inserting, removing, and creating and altering database tables and views. SQL is a query language rather than a database system.
This database language is primarily intended for use in relational database management systems to maintain data. It's a specialized tool that data professionals use to work with structured data (data which is stored in the form of tables).A person can quickly construct and operate the database, as well as access and modify table rows and columns, among other things. This query language was adopted as an ANSI standard in 1986 and an ISO standard in 1987.
Important points about SQL:
- Almost all relational databases utilize SQL to query, manipulate, and define data, as well as provide access control and a variety of other functions.
- Around 1970, IBM created SQL with Oracle as a major contribution, resulting in the SQL ANSI standard's implementation.
- SQL is a widely used computer language for managing relational databases and performing various operations on the data contained within them.
What SQL can do?
- SQL can be used to conduct queries against a database.
- SQL is a language that can be used to retrieve data from a database.
- SQL can be used to create new records in a database.
- In a database, SQL can be used to generate views.
- SQL can be used to update data in a database.
- SQL has the ability to delete records from a database.
- SQL has the ability to build new databases.
- SQL has the ability to create new tables in a database.
- In a database, SQL can create stored procedures.
- Dynamic SQL.
- Static SQL.
The database procedure's access is already determined in the statement in Static SQL. In Dynamic SQL, however, how the database is accessed can only be determined at run time.
2.Efficiency
Static SQL statements are very fast and efficient while as dynamic SQL statements are less efficient.
3.Compilation
Static SQL statements are compiled only the at compile time, whereas dynamic SQL statements are compiled only at the run time.
4.Use Cases
Static SQL is used in case of uniformly distributed data while as dynamic SQL is used in case of non-uniformly distributed data.
5.Dynamic Statements
In static SQL, statements such as EXECUTE IMMEDIATE, EXECUTE, and PREPARE are not utilized, however in dynamic SQL, statements such as EXECUTE IMMEDIATE, EXECUTE, and PREPARE are utilized.
6.Flexibility
Static SQL is less flexible than dynamic SQL, which is far more flexible.
Advantages of Embedded SQL
Small footprint database: Because embedded SQL relies on an Ultra-lite database engine that is custom-compiled for each application, the footprint is typically less than when utilizing an Ultra-lite component, especially for applications with a small number of tables. For the large number of tables, this benefit is usually lost.
High performance: Embedded SQL is an excellent choice for developing high-performance applications since it combines the very high performance of C and C++ applications with essentially the optimization of created code, including data access plans.
Some more advantages are:
- It helps to access the databases almost from anywhere.
- Allows to integrate the authentication service for very large scale applications.
- Provides an extra security to the database transactions.
- Avoids lot of the logical errors while performing the transactions on the database.
- Makes it very easy to integrate the frontend and backend of application.
Advantages of Dynamic SQL
Predicate Optimization: The most significant advantage of adopting dynamic SQL is that the execution plans generated for each and every query invocation are optimized for the predicates currently in use. Aside from the maintainability issue, the main difficulty with static SQL solutions is that the additional predicates confuse the query optimizer, forcing it to generate a large number of inefficient plans. By not providing anything more in the query, Dynamic SQL gets around this problem.
Single Query Plan Caching: There is only one cached query plan for each stored procedure in dynamic SQL, plus an additional ad hoc plan caches for each execution of the stored procedure. This means that every time a new argument is supplied to a stored process, a compilation will take place, thereby killing performance. Because the dynamic query is not parameterized, it generates a lot of duplicate query plans for different types of parameters.
Drawbacks of Embedded SQL
Knowledge of C or C++ required: If you don't know how to code in C or C++ programming, you may want to use one of the Ultra-lite interfaces. Ultra-lite components provide interfaces for a number of popular programming languages and tools.
Complex development model : The usage of a reference database to house the Ultra-lite database schema, as well as the requirement to preprocess the source code files, makes the embedded SQL development process extremely complicated. The Ultra-lite components greatly simplify the development process.- Static statements require regeneration of access plans if they were modified.
- They are less flexible
Drawbacks of Dynamic SQL
There are basically a lot of draw backs of using the dynamic SQL, however the stored procedures executes very fast than the dynamic SQL statements, because the application is basically only looking for the commands. The database program must generate code and then execute the code as asked when using dynamic SQL statements, which means it must handle a lot more data before looking for results. It then formats the findings which slows down the application even further.
Security concerns and the likelihood of errors are two further drawbacks of dynamic SQL. Because of the increased flexibility, it is much easier to detect and exploit code flaws. In addition, unlike stored procedures, dynamic SQL statements cannot be validated for every single instance. There is more freedom for very big databases because there are essentially no parameters, and the code is not written until the execution phase. It's far more difficult, if not impossible, to test for errors and conflicts.
Some other drawbacks of dynamic SQL are:
Permissions: Dynamic SQL require the users to have the direct access permissions on basically all accessed objects like the tables, views etc. Users usually have access to the stored procedures that refer to the tables, but not to the tables themselves. In this case, dynamic SQL will never work. Following are some additional drawbacks of dynamic SQL:
- A dynamic query's execution strategy cannot be cached.
- Debugging is quite difficult.
- Error management become quite unreliable.
- Unless they are global, temporary tables from the main statement cannot normally be used.
References
- https://www.tutorialspoint.com/sql/index.htm
- https://www.sqlshack.com/learn-sql-dynamic-sql/
- https://www.geeksforgeeks.org/difference-static-dynamic-sql/
- https://vivadifferences.com/difference-between-dynamic-and-static-sql-with-examples/
- https://afteracademy.com/blog/what-is-an-embedded-and-dynamic-sql



Great ! Really liked the idea to merge and for embedded SQL .
ReplyDeleteRight to the point. Nice work!
ReplyDeleteAll the contents are nicely explained!!π
ReplyDeleteNicely Explained ❤️
ReplyDeleteThanks a Lot ❤️
Very well explained π
ReplyDeleteAmazing write-up!
ReplyDeleteGreat work...π
Great π
ReplyDeleteSuperb....π
ReplyDeleteGreat work, very informative.
ReplyDeleteWell explained π
ReplyDeleteGreatπ
ReplyDeleteNiceπ
ReplyDeleteNice info!
ReplyDeletegreat work
ReplyDeletegood work
ReplyDeleteWell explained π
ReplyDeleteGreat work π
ReplyDeletehelpful πππ»
ReplyDeleteGood work
ReplyDeleteReally Helpful, Informative Content.
ReplyDeleteGood work
ReplyDeleteNice content
ReplyDeleteNice work and helpful content
ReplyDeleteVery informative
ReplyDeletenice work,informative,nice content
ReplyDeleteVery informative π€©!!!
ReplyDeleteNice work
ReplyDeleteVery informative
ReplyDeletehelpful content
ReplyDeleteAmazing write-up!
ReplyDeleteGood information
ReplyDeleteNice work
ReplyDeleteCommendable
ReplyDeleteVery much informative
ReplyDeleteAmazing work
ReplyDeleteLucid..great work π
ReplyDeletegood work
ReplyDeleteInformativeπ
ReplyDeleteNice work
ReplyDeleteAmazing work
ReplyDeleteπππ₯π₯
ReplyDeleteGreat π
ReplyDelete