我帮你写个吧:(我就写了两个字段,你自己根据自己的情况改动下)
create procedure InsertUserInfo
(@userId varchar(4),@userName varchar(50),@result integer output)
as
begin
if exists(select * from UserInfo where userName = @userName)
begin
set @result = -1;//判断是否已经存在要插入的昵称
end
begin
if exists(select * from UserInfo where
userId=@userId)
--判断在UserInfo表中是否已经存在此次插入的信息;
begin
set @result = 0;
end
else
begin
begin transaction tran_InsertUserInfo;
insert into UserInfo values(@userId,@userName);--插入到表
commit transaction tran_InsertUserInfo;
set @result = 1;
end
end
end
go