set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[AddUserOnChannel] @UserName varchar(50), @Password varchar(50), @ChannelID int, @Lock bit, @Remark text, @rtn int output--1成功-1失败 AS BEGIN declare @UserID int declare @tran varchar(50) set @rtn=-1; set @tran='1234' begin tran @tran begin try --插入用户信息 insert into [User] (UserName,Password,Remark,Lock) values ( @UserName, @Password, @Remark, @Lock ); --查找用户ID select @UserID=ID from [User] where userName=@UserName; --插入UserChannel表数据 insert into UserChannel ( UserID, ChannelID ) values ( @UserID, @ChannelID ) set @rtn=1; end try begin catch if @@trancount>0 rollback tran @tran; end catch if @@trancount>0 commit tran @tran; END
感谢田老表...