⟩ How To Create a Stored Procedure with a Statement Block in MS SQL Server?
If you are creating a stored procedure with multiple statements, it's better to use "BEGIN ... END" to group all statements into a single statement block.
The tutorial exercise below shows you some good examples:
USE GlobalGuideLineDatabase;
GO
CREATE PROCEDURE Show AS BEGIN
SELECT name, type_desc FROM sys.tables;
SELECT name, type_desc FROM sys.views;
SELECT name, type_desc FROM sys.procedures;
END;
GO
Command(s) completed successfully.
EXEC Show;
GO
name type_desc
------------------- ---------------------
ggl_random USER_TABLE
ggl_links_indexed USER_TABLE
ggl_links USER_TABLE
ggl_links_copy USER_TABLE
name type_desc
------------------- ---------------------
ggl_links_top VIEW
ggl_links_dump VIEW
ggl_links_view VIEW
name type_desc
------------------- ---------------------
Hello SQL_STORED_PROCEDURE
date SQL_STORED_PROCEDURE
Show SQL_STORED_PROCEDURE