set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[usertest]
@username nvarchar(1000),
@pwd int
AS
declare @newid int
BEGIN
if(@pwd>0)
begin
begin transaction
Insert into usertable (username,pwd) values (@username,@pwd)
set @newid=@@identity
Insert into usertable (username,pwd) values (@newid,@newid)
if(@@identity=126)
begin
commit transaction --提交事务
end
else
begin
ROLLBACK transaction--回滚实物(删除了刚才执行的操作)
end
end
END
go
exec usertest 'Name01','21'