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
Related questions
+2
votes
Q: What is the difference between PARTITION BY and GROUP BY
asked
Jan 15, 2022
in
Sql
by
GeorgeBell
t-sql
+2
votes
Q: What's the difference between TRUNCATE and DELETE in SQL?
asked
Jan 15, 2022
in
Sql
by
GeorgeBell
t-sql
+2
votes
Q: Is there a difference between T-SQL linked server and a synonym?
asked
Jan 14, 2022
in
Sql
by
GeorgeBell
t-sql
+2
votes
Q: What are the practical differences between COALESCE() and ISNULL(,'')?
asked
Jan 15, 2022
in
Sql
by
GeorgeBell
t-sql
0
votes
Q: what are dynamic queries in T-SQL?
asked
Dec 24, 2023
in
Sql
by
john ganales
t-sql
+1
vote
Q: How would you prevent T-SQL code from running on a production SQL Server?
asked
Jan 15, 2022
in
Sql
by
GeorgeBell
t-sql
+1
vote
Q: What is the use of GO in Transact SQL?
asked
Jan 15, 2022
in
Sql
by
GeorgeBell
t-sql
+2
votes
Q: Is it possible to import data directly from T-SQL commands without using SQL Server Integration Services? If so, what are the commands?
asked
Jan 15, 2022
in
Sql
by
GeorgeBell
t-sql
+2
votes
Q: What are types of XML indexes in SQL Server?
asked
Jan 15, 2022
in
Sql
by
GeorgeBell
t-sql
+2
votes
Q: What are bitwise operators and what is the value from a database design perspective?
asked
Jan 15, 2022
in
Sql
by
GeorgeBell
t-sql
...