存储过程,又称存储程序(英语:Stored Procedure),是在数据库存储复杂程序,以便外部程序调用的数据库对象,可以视为数据库的一种函数或子程序。
存储过程具有下列的好处:
存储过程是数据库对象之一,必须使用数据定义语言来创建,例如:
CREATE PROCEDURE usp_AddProduct( @Barcode varchar(13), @Caption nvarchar(50))ASBEGIN IF LEN(@Barcode) < 13 RAISERROR('Barcode length is too short.') INSERT INTO MyProducts (Barcode, Caption) VALUES (@Barcode, @Caption)END