SQL CREATE PROCEDURE Keyword
The CREATE PROCEDURE command is used to define a stored procedure. A stored procedure is a pre-written block of SQL code that can be executed repeatedly to perform specific tasks such as querying data or modifying tables.
SQL CREATE PROCEDURE Syntax
SQL
x
1
CREATE PROCEDURE procedure_name
2
AS
3
SQL statements
SQL CREATE PROCEDURE Example
This procedure is intended to return all records from the Patients table each time it is executed.
SQL
1
1
CREATE PROCEDURE SelectAllPatients
2
AS
3
SELECT * FROM Patients
4
GO
Execution:
This runs the stored procedure and displays the result of the query.
SQL
1
1
EXEC SelectAllPatients
Note: This example will in the TechKubo playground. SQLite does not support CREATE PROCEDURE or stored procedures. Stored procedures are supported in other systems like SQL Server MySQL and Oracle.