Click here to Skip to main content
15,888,297 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai All, I am new to SQL. I would like to know why we use EXEC in sql?

Thanks and Regards,
Posted

EXEC is used to execute SPs in SQL SERVER.
 
Share this answer
 
Quote:
Executes a command string or character string within a Transact-SQL batch, or one of the following modules: system stored procedure, user-defined stored procedure, CLR stored procedure, scalar-valued user-defined function, or extended stored procedure. The EXECUTE statement can be used to send pass-through commands to linked servers.

Example

EXEC sp_help; -- sp_help is a built in function. this command is used to execute sp_help.

like this stored procedures are executed by using EXEC command.
 
Share this answer
 
 
Share this answer
 
Further to solutions 1 and 2 (and note it can be used for more than just stored procedures), you should read this post[^] and the articles linked within it - it discusses the differences between EXEC and sp_executesql and how the latter is better to avoid sql injection[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900