添加新用户存储过程AddUser
1
2CREATE Procedure AddUser
3(
4 @UserName nvarchar(50),
5 @Password nvarchar(50),
6 @Name nvarchar(50),
7 @Email nvarchar(50),
8 @Sex nvarchar(50),
9 @IDCardNumber nvarchar(50),
10 @Telephone nvarchar(50),
11 @Address nvarchar(50),
12 @Zipcode nvarchar(50),
13 @Problem nvarchar(50),
14 @Answer nvarchar(50),
15 /* @Integral float(8), */
16 @UserID int OUTPUT
17)
18AS
19 /*检查是否存在相同的userName*/
20 if(not exists(select * from UserInfo where UserName=@UserName))
21 BEGIN
22 /*不存在则插入新记录,否则返回-1*/
23 INSERT INTO UserInfo(UserName,Password,Name,Email,Sex,IDCardNumber,
24 Telephone,Address,Zipcode,Problem,Answer)
25 VALUES(@UserName,@Password,@Name,@Email,
26 @Sex,@IDCardNumber,@Telephone,@Address,
27 @Zipcode,@Problem,@Answer)
28 SELECT @UserID=@@identity
29 END
30 ELSE BEGIN
31 SET @UserID=-1
32 END
33
34GO
35
2CREATE Procedure AddUser
3(
4 @UserName nvarchar(50),
5 @Password nvarchar(50),
6 @Name nvarchar(50),
7 @Email nvarchar(50),
8 @Sex nvarchar(50),
9 @IDCardNumber nvarchar(50),
10 @Telephone nvarchar(50),
11 @Address nvarchar(50),
12 @Zipcode nvarchar(50),
13 @Problem nvarchar(50),
14 @Answer nvarchar(50),
15 /* @Integral float(8), */
16 @UserID int OUTPUT
17)
18AS
19 /*检查是否存在相同的userName*/
20 if(not exists(select * from UserInfo where UserName=@UserName))
21 BEGIN
22 /*不存在则插入新记录,否则返回-1*/
23 INSERT INTO UserInfo(UserName,Password,Name,Email,Sex,IDCardNumber,
24 Telephone,Address,Zipcode,Problem,Answer)
25 VALUES(@UserName,@Password,@Name,@Email,
26 @Sex,@IDCardNumber,@Telephone,@Address,
27 @Zipcode,@Problem,@Answer)
28 SELECT @UserID=@@identity
29 END
30 ELSE BEGIN
31 SET @UserID=-1
32 END
33
34GO
35