Home
Recent Q&A
Java
Cloud
JavaScript
Python
SQL
PHP
HTML
C++
Data Science
DBMS
Devops
Hadoop
Machine Learning
Azure
Blockchain
Devops
Ask a Question
What is the difference between EXEC vs sp_executesql?
Home
Sql
What is the difference between EXEC vs sp_executesql?
+2
votes
asked
Jan 15, 2022
in
Sql
by
GeorgeBell
What is the difference between EXEC vs sp_executesql?
t-sql
Please
log in
or
register
to answer this question.
1
Answer
0
votes
answered
Jan 15, 2022
by
GeorgeBell
Besides the usage, there are some important differences:
sp_executesql
allows for statements to be parameterized. Therefore It’s more secure than
EXEC
in terms of SQL injection
sp_executesql
can leverage cached query plans. The TSQL string is built only one time, after that every time same query is called with
sp_executesql
, SQL Server retrieves the query plan from cache and reuses it
Temp tables created in
EXEC
can not use temp table caching mechanism
...