BEGIN
SET NOCOUNT ON;
if @_MODE NOT IN (‘A‘,‘M‘,‘D‘)
begin
raiserror(‘参数错误!‘,16,3);
return;
end;
declare @rowcount int,@error int;
if @_MODE=‘A‘
begin
insert into szdxInfo (Id,Bh,[Name],nation) select
@Id,@Bh,@Name,
@Nation;
if @@error<>0 return;
end;
if @_MODE=‘M‘
begin
update szdxInfo set [Name][email protected],
[email protected]
where [email protected];
select @[email protected]@error,@[email protected]@rowcount;
if @error<>0 return;
if @rowcount<>1
begin
raiserror(‘没有修改记录!!‘,16,3)
return;
end;
end;
if @_MODE=‘D‘
begin
delete szdxInfo where [email protected];
select @[email protected]@error,@[email protected]@rowcount;
if @error<>0 return;
if @rowcount<>1
begin
raiserror(‘没有删除记录!!‘,16,3)
return;
end;
end;
insert into ActionLog ([date],[userid],Computerid,
TableName,[Action]) select
getdate(),@_USERID,
@_COMPUTERID,
‘szdxInfo‘,@_MODE;
/*
exec Update_szdxInfo @id=‘11‘,
@Name =‘刘某某‘,
@Nation =‘汉族‘,
@_MODE =‘A‘,
@_USERID=1,
@_COMPUTERID=1
select * from szdxINfo
*/
END
原文地址:https://www.cnblogs.com/james_chen/p/9125980.html