ifexists (select1from sys.objects where name ='DeleteUser'and type ='P') dropprocedure[dbo].[DeleteUser] GO CREATEPROCEDURE DeleteUser @UserIDint AS DELETEFROM Users WHERE UserID =@UserID GO
3.3 更新用户Email
ifexists (select1from sys.objects where name ='UpdateUserEmail'and type ='P') dropprocedure[dbo].[UpdateUserEmail] GO CREATEPROCEDURE UpdateUserEmail @UserIDint , @Emailvarchar(255) AS UPDATE Users Set Email =@Email Where UserID =@UserID GO
3.4 验证登录
ifexists (select1from sys.objects where name ='ValidateLogin'and type ='P') dropprocedure[dbo].[ValidateLogin] GO CREATEPROCEDURE[dbo].[ValidateLogin] @UserNamevarchar(16), @CryptPasswordvarchar(60) AS SELECT UserID FROM Users WHERE UserName =@UserNameAND Password =@CryptPassword GO
3.5 返回所有可用用户信息
ifexists (select1from sys.objects where name ='GetUsers'and type ='P') dropprocedure[dbo].[GetUsers] GO CREATEPROCEDURE[dbo].[GetUsers] AS SELECT UserID, UserName, Nickname, Email, Question, Answer, Sex, ShowEmail, Signature, ImageUrl, AddedDate FROM Users GO
3.6 根据用户名得到用户id
ifexists (select1from sys.objects where name ='GetUserIDByUserName'and type ='P') dropprocedure[dbo].[GetUserIDByUserName] GO CREATEPROCEDURE[dbo].[GetUserIDByUserName] @UserNamevarchar(16) AS SELECT UserID FROM Users WHERE UserName =@UserName GO
本节主要创建网站后续使用到的用户表及相关存储过程1.创建数据库打开SQL Server Management Studio,在查询窗口执行以下T-SQL语句 IF EXISTS (SELECT 1 FROM sys.databases WHERE name = NWish) DROP DATABASE [Wish]GO CREATE DATABASE [Wish