In SQL, a storedprocedure is a pre-compiled collection of SQL statements and procedural logic that can be executed repeatedly by invoking the procedure. Stored procedures are stored in the database and can be used to encapsulate complex business logic, improve performance, and simplify database administration.
Here's an example of how to create a stored procedure in SQL Server to find a student record by their stu_ID from the student table:
CREATE PROCEDURE find_student
@stu_ID INT
AS
BEGIN
SELECT * FROM student WHERE stu_ID = @stu_ID
END
In this example, the CREATE PROCEDURE statement is used to create a stored procedure called find_student. The procedure takes one input parameter, @stu_ID, which is an integer representing the student ID.
The SELECT statement is used to retrieve the student record from the student table where the stu_ID matches the input parameter @stu_ID.
To execute the stored procedure, you can use the EXECUTE statement, passing in the value of @stu_ID as a parameter:
EXECUTE find_student @stu_ID = 12
This will return the student record from the student table where the stu_ID is 12.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
In SQL, a stored procedure is a pre-compiled collection of SQL statements and procedural logic that can be executed repeatedly by invoking the procedure. Stored procedures are stored in the database and can be used to encapsulate complex business logic, improve performance, and simplify database administration.
Here's an example of how to create a stored procedure in SQL Server to find a student record by their stu_ID from the student table:
In this example, the CREATE PROCEDURE statement is used to create a stored procedure called find_student. The procedure takes one input parameter, @stu_ID, which is an integer representing the student ID.
The SELECT statement is used to retrieve the student record from the student table where the stu_ID matches the input parameter @stu_ID.
To execute the stored procedure, you can use the EXECUTE statement, passing in the value of @stu_ID as a parameter:
This will return the student record from the student table where the stu_ID is 12.