SQL-创建存储过程
/* 日期:2021-3-6 人员:LDH 说明:SQL-演示存储过程 */ USE TEST; GO CREATE TABLE People ( Id INT IDENTITY(1, 1) NOT NULL PRIMARY KEY, Name NVARCHAR(20) NOT NULL, Lastname NVARCHAR(10) NOT NULL, Address NVARCHAR(200) NOT NULL ); INSERT INTO People ( Name, Lastname, Address ) VALUES (N'大大', N'李', '中国上海'), (N'小小', N'孙', '中国江苏'); SELECT Id, Name, Lastname, Address FROM People; -- =================================================================== -- 创建存储过程(无参数) -- =================================================================== GO CREATE PROCEDURE proc_GetPersonName AS BEGIN SELECT Id, Name, Lastname, Address FROM People; END; -- 执行存储过程 EXEC proc_GetPersonName; GO -- =================================================================== -- 创建存储过程(有输入参数) -- =================================================================== CREATE PROCEDURE proc_GetPersonNameById @Id int AS BEGIN SELECT Id, Name, Lastname, Address FROM People WHERE Id = @Id; END; -- 执行存储过程 EXEC proc_GetPersonNameById 2; GO -- =================================================================== -- 创建存储过程(有输出参数) -- =================================================================== CREATE PROCEDURE proc_GetPersonFullNameAndAddressById ( @Id int, @FullName nvarchar(50) OUTPUT, @Address nvarchar(200) OUTPUT ) AS BEGIN SELECT @FullName = Lastname + Name, @Address = Address FROM People WHERE Id = @Id; END; -- 执行存储过程 USE [TEST]; GO DECLARE @return_value INT, @FullName NVARCHAR(50), @Address NVARCHAR(200); EXEC @return_value = [dbo].[proc_GetPersonFullNameAndAddressById] @Id = 2, -- 输入参数赋值 @FullName = @FullName OUTPUT, @Address = @Address OUTPUT; SELECT @FullName AS N'@FullName', @Address AS N'@Address'; SELECT 'Return Value' = @return_value; GO
本文作者:Love In Winter
本文链接:https://www.cnblogs.com/LifeDecidesHappiness/p/14490879.html
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以扫一扫,任意打赏,您的鼓励是博主的最大动力!
本文链接:https://www.cnblogs.com/LifeDecidesHappiness/p/14490879.html
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以扫一扫,任意打赏,您的鼓励是博主的最大动力!
![扫一扫,支付宝打赏](https://files.cnblogs.com/files/LifeDecidesHappiness/%E6%94%AF%E4%BB%98%E5%AE%9D.bmp)
![扫一扫,微信打赏](https://files.cnblogs.com/files/LifeDecidesHappiness/%E5%BE%AE%E4%BF%A1%E6%94%B6%E6%AC%BE%E7%A0%81.bmp)