存储过程输出输入

来源:互联网 发布:为什么移动4g网络很慢 编辑:程序博客网 时间:2024/06/07 05:58

需求:自增长ID作为主键的表,如何在插入的同时获取主键

实现方式:存储过程OUTPUT

1、创建自增长表

create table a(id int identity(1,1),b int)

2、编写存储过程
GOcreate procedure [dbo].[p_identity]@in int -- 输入,@out int output --输出ASinsert into a(b) values(@in)select @out = @@identity


3、实验调用

GOdeclare @out int exec [p_identity] 2,@out output

结果验证 



4、删除测试数据

drop procedure [dbo].[p_identity]drop table a


0 0
原创粉丝点击