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 |
How do indexes help, types?
List some advantages and disadvantages of stored procedure?
How to update multiple rows with one update statement in ms sql server?
Benefits of Stored Procedures?
How will you monitor replication activity and performance? What privilege do you need to use replication monitor? : sql server replication
Explain DBMS, RDBMS?
Can anyone explain difference between Database, Data warehouse and Data mart with some example?````
Where is trigger in sql server?
What are diverse clauses that form a part of sql?
what is a join and explain different types of joins? : Sql server database administration
What is left outer join in sql server joins?
What is transaction ? Give me one example.
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)