Static or embedded SQL are SQL statements in an application that do not change at runtime and therefore can be hard-coded into the application. Dynamic SQL is a SQL statement constructed at run time. For example, an application can allow users to enter their own queries.
Dynamic SQL is a programming technology that enables you to dynamically construct SQL statements at runtime. You can create more versatile, flexible applications using dynamic SQL because the full text of a SQL statement may not be known at compile time.
Recommended reference study: "mysql tutorial"
Mentioned below are the basic differences between Static or Embedded and Dynamic or Interactive SQL :
Static (embedded) SQL | Dynamic (interactive) SQL |
In Static SQL , the embedded SQL statement predetermines how to access the database. | In Dynamic SQL, how to access the database is determined at runtime. |
It is faster and more effective. | It's not as fast and efficient. |
SQL statements are compiled at compile time. | SQL statements are compiled at runtime. |
Parsing, verification, optimization and application plan generation are completed at compile time. | Parsing, validation, optimization and generation of application plans are completed at runtime. |
It is usually used when the data is evenly distributed. | It is usually used when the data distribution is uneven. |
Do not use EXECUTE IMMEDIATE, EXECUTE and PREPARE statements. | Use EXECUTE IMMEDIATE, EXECUTE and PREPARE statements. |
It is less flexible. | It is more flexible. |
Limitations of dynamic SQL:
We cannot use certain SQL statements dynamically.
The performance of these statements is poor compared to Static SQL.
Limitations of static SQL:
They do not change at runtime and therefore are hard-coded into the application.
This article is about the difference between static and dynamic sql. I hope it will be helpful to friends in need!
The above is the detailed content of what is the difference between static and dynamic sql. For more information, please follow other related articles on the PHP Chinese website!