SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sp_executesql vs exec


sp_executesql vs exec

Author
Message
deepikamm
deepikamm
SSC-Enthusiastic
SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)

Group: General Forum Members
Points: 129 Visits: 201
Kindly explain the following

EXEC
sp_executesql
dynamic sql
exec vs sp_executesql

I am not sure whether i can ask all the questions in a single thread.I am sorry if i have breached the posting rules of sqlservercentral.:-)
poojari045
poojari045
Valued Member
Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)

Group: General Forum Members
Points: 50 Visits: 59
All these are available in BOL.
Loundy
Loundy
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1846 Visits: 1190
exec or execute

http://msdn.microsoft.com/en-us/library/ms188332.aspx

sp_executesql

http://msdn.microsoft.com/en-us/library/ms188001.aspx

simples.

There's no kill switch on awesome!
Divine Flame
Divine Flame
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2353 Visits: 2816
deepikamm (1/31/2012)
Kindly explain the following

EXEC
sp_executesql
dynamic sql
exec vs sp_executesql

I am not sure whether i can ask all the questions in a single thread.I am sorry if i have breached the posting rules of sqlservercentral.:-)


1. EXEC : EXEC/Execute is used to execute any stored procedure or character string. Mostly it is used to execute the stored procedure.

2. SP_ExecuteSQL: SP_ExecuteSQL is used to execute ad-hoc SQL statements so that they can be executed as parameterized statements. It helps to boost the performance of the server as same statements are not frequently compiled.

3. Dynamic SQL: It is when we preapare the SQL statements on the fly. Most of the times SP_ExecuteSQL is used to execute dynamic SQL.

4. EXEC vs SP_ExecuteSQL : Differences given above.

For further reading click on below links:

EXEC/Execute

SP_ExecuteSQL

Dynamic SQL


Sujeet Singh
deepikamm
deepikamm
SSC-Enthusiastic
SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)

Group: General Forum Members
Points: 129 Visits: 201
Thank you all for quick response.

I am expecting layman explanation on these topics and I am tired of reading msdn.
deepikamm
deepikamm
SSC-Enthusiastic
SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)

Group: General Forum Members
Points: 129 Visits: 201
To be more precise,I am expecting blogs or articles on these topics.

(plz don't direct me to microsoft blogs:w00tSmile
Divine Flame
Divine Flame
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2353 Visits: 2816
deepikamm (1/31/2012)
Thank you all for quick response.

I am expecting layman explanation on these topics and I am tired of reading msdn.


I think we have provided the layman definition. If you want anything special OR if we were not clear at any point about these keywords you may ask that as well.


Sujeet Singh
Divine Flame
Divine Flame
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2353 Visits: 2816
deepikamm (1/31/2012)
To be more precise,I am expecting blogs or articles on these topics.

(plz don't direct me to microsoft blogs:w00tSmile


Every msdn article has provided well written examples also so they are the primary source to read. However, the third link in my first post is a good article about SP_ExecuteSQL. A good article on the same topic is todays topic on the SQLServerCentral home page (you missed :-P).

http://www.sqlservercentral.com/articles/nHibernate/86913/


Sujeet Singh
deepikamm
deepikamm
SSC-Enthusiastic
SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)SSC-Enthusiastic (129 reputation)

Group: General Forum Members
Points: 129 Visits: 201
after seeing sp_executesql in sqlservercentral homepage,I started searching about it.
Divine Flame
Divine Flame
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2353 Visits: 2816
deepikamm (1/31/2012)
after seeing sp_executesql in sqlservercentral homepage,I started searching about it.


Seeing !!!? Didn't you read the article?

David shows the use of SP_ExecuteSQL when he executes this code in his article:


USE AdventureWorks
go

DECLARE
@EmployeeID int,
@Statement nvarchar(2000),
@ParamDefinitions nvarchar(2000)

SET @Statement = N'SELECT * FROM HumanResources.Employee WHERE ManagerId=@ManagerID AND MaritalStatus=@MaritalStatus'
SET @ParamDefinitions = N'@ManagerID INT,@MaritalStatus char(1)'

exec sp_executesql @statement, @ParamDefinitions,@ManagerID=21,@Maritalstatus='S'




He clearly explains how SP_ExecuteSQL helps to use the plan stored in the cache even after chainging the parameter values Cool.


Sujeet Singh
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search