What is the difference between static and dynamic SQL?
Static SQL is SQL statements in an application that do not change at runtime and, therefore, can be hard-coded into the application.Static SQL is usually targeted at a specific database and in many cases gets stored in stored procedures. Many applications (especially Enterprise Applications) reach a stage where some dynamic data manipulation is required and static SQL techniques no longer sufficient.
Dynamic SQL is SQL statements that are constructed at runtime. Dynamic SQL generation is also needed in applications where the databases structure itself is dynamic. Many Enterprise Applications allow users to customize the way data is stored and displayed.
for example, the application may allow users to enter their own queries. Thus, the SQL statements cannot be hard-coded into the application.
Static SQL provides performance advantages over dynamic SQL because static SQL is preprocessed, which means the statements are parsed, validated, and optimized only once.