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 |
Explain “@@rowcount” and “@@error” in sql server?
Which language is supported by sql server?
What is a transact-sql statement batch in ms sql server?
John exports information periodically from a microsoft sql server database to an oracle database what is the best way to do this?
What is a function? Give some example?
What happens when unicode strings concatenate with non-unicode strings?
explain what is a schema in sql server 2005? Explain how to create a new schema in a database? : Sql server database administration
How to delete multiple rows with one delete statement in ms sql server?
Tell me about normalization in DBMS.
Explain why variables called the most powerful component of ssis?
hi,i want t0 knom d syntax for a super key with an example
How does normalization work?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)