Custom SQL vs Dynamic SQL
Jun 29, 2015 21:51 2 Comments Adapters Shabd

Custom vs Dynamic SQL:



In Custom SQL, SQL query (statement) is fixed. In Dynamic SQL, query is not fixed rather it changes dynamically.

 


  • In Custom SQL, you can pass inputs to your SQL query at run time. With Dynamic SQL, you can pass your entire SQL statement, or part of your SQL statement can be passed at run time; along with inputs to it. So basically you can build your SQL dynamically at runtime.

  • You use Custom SQL when SQL query is fixed with input variable that are passed to the custom adapter service. You use dynamic SQL, if SQL query changes during the runtime; in this cases you prepare the sql query and pass it to dynamic adapter service in the runtime.

  • Custom SQL and Dynamic SQL we have to write the queries explicitly. The main difference between Custom SQL and Dynamic SQL is; in Custom SQL we can give the input values at design time. In Dynamic SQL we can give the input values at run time.

  • Custom SQL is faster than the Dynamic SQL because Custom SQL is pre-compiled (at design time) but dynamic SQL is not pre-compiled (compiled at runtime). 

  • Dynamic SQL is more versatile than the Custom SQL.




 

 

Example:

Custom SQL:   

SELECT a.FirstName, a.LastName, a.EmpoyeeID, a.City

FROM EmployeeDetails a

WHERE a.SSN=?

 

Dynamic SQL:  

SELECT a.FirstName, a.LastName, a.EmpoyeeID, a.City

FROM    EmployeeDetails a

 

WHERE a.SSN=? AND ${condition}      

// Here condition can be build dynamically, for e.g; a.TaxID=?

 

SELECT ${columnName} AS PostalCode

FROM LocationDetails

 

WHERE EmployeeID=? AND LocationID=?

//Here columnName string can be prepared dynamically based on the what information is needed.

 

Also you can build the entire SQL dynamically based on what information is needed from what tables. For Example,${sqlQuery}.

 



Prev Next
About the Author
Topic Replies (2)
  1. 1
    idnkx user

    Itzgani

    Custom SQL is faster than the Dynamic SQL.
    Because Custom SQL is pre-compiled (at design time) where as dynamic SQL is not pre-compiled (compiled at runtime).

    1
    idnkx user

    Cali CBD Reviews

    mysql and sql server main deference's?

Leave a Reply
Guest User

You might also like

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.


Let`s Connect