What is the diff between Static Queries and Dynamic queries
give me some examples
Answers were Sorted based on User's Feedback
Answer / praveen
Static queries are the queries we normally use like SELECT *
FROM EMPLOYEE. where as dynamic queries can be built and
executed dynamically. sp_executesql system stored procedure
is used to execute dynamic sql statements.
Eg: sp_executesql N'select * from employee'
dynamic sql queries will take more time to execute when
compared to static queries
Is This Answer Correct ? | 18 Yes | 5 No |
Static Queries are permanent and cannot be changed during run-time, like: "SELECT * FROM Employees"
Dynamic Queries can be changed during run-time as they are created by using variables and these variables contain parts of SQL Query, like:
DECLARE @SQL VARCHAR(MAX)
DECLARE @WHENSQL VARCHAR(2000)
DECLARE @SEARCHSQL VARCHAR(500)
SELECT @WHENSQL = 'EmployeeID'
SELECT @SEARCHSQL = '100'
SELECT @SQL = 'SELECT * FROM Employees WHERE ' + @WHENSQL + ' = ' + @SEARCHSQL
EXEC (@SQL)
-- or
EXEC sp_executesql @SQL
For more interview Questions on SQL Server: http://sqlwithmanoj.wordpress.com/interview-questions/
Is This Answer Correct ? | 1 Yes | 0 No |
Do you know what is difference between index seek vs. Index scan?
What are window functions in sql server?
If a stored procedure is taking a table data type, how it looks?
what is sql injection in sql server?
Differentiate between a primary key and a unique key.
Explain the architecture of ms sql reporting service?
What is similarity and difference between truncate and delete in sql?
How to add code to the existing article (using improve article)?
what are user defined datatypes? : Sql server database administration
List the types of recovery model available in sql server?
How to use "begin ... End" statement structures in ms sql server?
Should you normalize audio?