Microsoft SQL Server

STORE PROCEDURE in SQL Server

A stored procedure is a named group of SQL statements that have been previously created and stored in the server database.

Stored procedures accept input parameters so that a single procedure can be used over the network by
several clients using different input data. And when the procedure is modified, all clients automatically get the new version.

Stored procedures reduce network traffic and improve performance.

Stored procedures can be used to help ensure the integrity of the database.

 CREATE PROCEDURE usp_SelectRecord  
AS
BEGIN
SELECT * FROM TABLE
END
GO

Error Handling in SQL Server

 CREATE PROCEDURE procedure_name AS  
BEGIN TRY
PRINT 'My name is Himen'
SELECT * FROM dbo.Users
PRINT 'This will not print - My name is Himen'
END TRY
BEGIN CATCH
PRINT 'And nor does this print'
END CATCH
go

Leave a comment