Day 80 – Stored Procedures
Stored Procedures: These are pre-compiled SQL statements that are stored in the database and can be executed multiple times. They are useful in reducing network traffic by allowing the client to execute a single procedure call instead of multiple SQL statements. Stored procedures can also be used to enforce business rules and provide a level of security by controlling data access.
CREATE PROCEDURE spGetCustomers
AS
BEGIN
SELECT * FROM Customers
END
EXEC spGetCustomers
In this example, a stored procedure named spGetCustomers
is created to retrieve all customers from the Customers
table. The procedure is then executed using the EXEC
statement.