存储过程获取最后插入到数据表里面的ID

存储过程获取最后插入到数据表里面的ID

 

SET NOCOUNT on;---不返回影响行数提高性能
GO
create proc [sp_bbs_thread_Insert]

@id int output,
@title varchar(255),@content text,  @userid int, @typeid int,

@catalogid int........--许多参数

insert into(un1,un2,,,)values(,,,,)--一个添加到数据库里面的方法
SELECT @id = SCOPE_IDENTITY();--返回插入到标识列中的值---获取刚刚插入到上面的ID

 

while(1=1)
begin
update bbs_catalog set threadCount=threadCount+1,lastThreadId=@id where id=@catalogid
select @catalogid=parentId from bbs_catalog where Id=@catalogid
if(@catalogid=0)
break;
end

posted @ 2016-01-21 11:05  无处安放的青春  阅读(1421)  评论(0编辑  收藏  举报