4.1. SYNTAX AND EXAMPLE

 

  • A stored procedure is a collection and set of sql statements and sql command logic which is compiled and stored in the database. A stored procedure is one kind of database object which is available under programmability section.
  • We can reused one stored procedure where-ever we require it in programming because in stored procedure we are writing processing, and insert and update, and delete.


EXAMPLE: - CREATE PROCEDURE SelectAllCustomers

AS

SELECT * FROM Customers


EXECUTION: - EXEC SelectAllCustomers;



Stored Procedure with Multiple Parameters


EXAMPLE: - CREATE PROCEDURE SelectAllCustomers

@City nvarchar(30), @PostalCode nvarchar(10) 

AS

Begin

SELECT * FROM Customers WHERE City = @City AND

PostalCode = @PostalCode

End


EXECUTION: - EXEC SelectAllCustomers ‘London’, ‘WA1 1DP’;

Last modified: Tuesday, 17 December 2019, 1:01 PM