Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What is the difference between static sql and dynamic sql?


Asked by Braden Swanson on Dec 12, 2021 SQL



In Static SQL, database access procedure is predetermined in the statement. In Dynamic SQL, how a database will be accessed, can be determine only at run time. Static SQL statements are more faster and efficient. Dynamic SQL statements are less efficient.
In this manner,
The same SQL can be considered static or dynamic depending on how it is executed. In this post, I’m going to show how the same SQL statement can be done statically or dynamically. The example SQL statement we’ll use is: UPDATE DB2.USER set EMAIL=upper (?) where user_id=?
Besides, Usually, Dynamic SQL is generally slower than static SQL because the database management system has to create an access plan at runtime for dynamic SQL statements.
In respect to this,
In Static or Embedded SQL, how the database will be access procedure is predetermined in the embedded SQL statement and performed by the preprocessor where user cannot run queries on runtime. All processes including Parsing, validation, optimization and generation of application access plan are done at compile time.
And,
1.In dynamic SQL, how database will be accessed is determined at run time. 2.It is less swift and efficient. 3.SQL statements are compiled at run time. 4.Parsing, validation, optimization, and generation of application plan are done at run time.