mssql,procedure,tran,transaction,事务,数据库事务,获取上一次的ID
2008-07-01 12:25 Virus-BeautyCode 阅读(763) 评论(0) 编辑 收藏 举报create procedure AddUserInfo
@LoginName varchar(50),
@Password varchar(50),
@Remark varchar(200),
@RealName varchar(50),
@RoleID int,
@lastID int output
as
begin tran
insert into dbo.SysUserInfo(LoginName,[Password],Remark,RealName) values(@LoginName,@Password,@Remark,@RealName)
select @lastID=scope_identity()
insert into UserRoleInfo(UserInfoAutoID,RoleInfoAutoID) values(@lastID,@RoleID)
if @@error<>0
begin
rollback tran
end
else
begin
commit tran
end
go
@LoginName varchar(50),
@Password varchar(50),
@Remark varchar(200),
@RealName varchar(50),
@RoleID int,
@lastID int output
as
begin tran
insert into dbo.SysUserInfo(LoginName,[Password],Remark,RealName) values(@LoginName,@Password,@Remark,@RealName)
select @lastID=scope_identity()
insert into UserRoleInfo(UserInfoAutoID,RoleInfoAutoID) values(@lastID,@RoleID)
if @@error<>0
begin
rollback tran
end
else
begin
commit tran
end
go