7-DBMS- Dynamic SQL
7-DBMS- Dynamic SQL
Akhilesh Arya
Static VS Dynamic SQL
• Static SQL refers to those SQL statements which
are fixed and can be hard coded into the
application.
• Dynamic SQL refers to those SQL statements
which are generated dynamically based on
user's input and run in the application
• Dynamic Sqls helps to develop general and
flexible applications
Cont..
• Dynamic SQL is the process that we follow for
programming SQL queries in such a way that the
queries are built dynamically with the application
operations.
• With dynamic SQL we are free to create flexible SQL
queries and the names of the variables or any other
parameters are passed when the application runs.
Cont..
• It helps us to manage big industrial
applications and manage the transactions
without any added overhead.
• For Dynamic SQL, we use the exec or
execute keyword.
# Start by declaring the Query variable and other required variables
DECLARE @SQL nvarchar(1000)
DECLARE @variable1 varchar(50)
DECLARE @variable2 varchar(50)