일련의 쿼리를 마치 하나의 함수처럼 실행하기 위한 쿼리의 집합
A stored procedure is a prepared SQL code that you can save, so the code can be reused over and over again.
So if you have an SQL query that you write over and over again, save it as a stored procedure, and then just call it to execute it.
You can also pass parameters to a stored procedure, so that the stored procedure can act based on the parameter value(s) that is passed.
기본 문법
CREATE PROCEDURE procedure_name
AS
sql_statement
GO;
실행
EXEC SelectAllCustomers;
파라미터가 있는 경우
CREATE PROCEDURE SelectAllCustomers @City nvarchar(30), @PostalCode nvarchar(10)
AS
SELECT * FROM Customers WHERE City = @City AND PostalCode = @PostalCode
GO;
EXEC SelectAllCustomers @City = 'London', @PostalCode = 'WA1 1DP';