EXEC
EXEC, also known as EXECUTE, is a SQL command used to execute a stored procedure or a function. It runs the SQL code contained within these procedures or functions which can include SELECT, UPDATE, INSERT, and DELETE commands, among others. This command is beneficial in reducing redundancy in SQL code by allowing same set of commands to be reused multiple times.
Example
Output
Explanation
The example demonstrates the use of EXEC
command. First, we create a procedure named MyProcedure
using CREATE PROCEDURE
which prints ‘Hello World’. After that, we execute the procedure using the EXEC
command. The output is the string ‘Hello World’ printed by the executed procedure.