导航

alter proc CustomerEnrol
(
  @FullName nvarchar(50),
  @UserPassword nvarchar(50),
  @EmailAddress nvarchar(50)
)
as
insert into Customers(FullName,UserPassword,EmailAddress) values(@FullName,@UserPassword,@EmailAddress)
select @@identity as CustomerID
go

结果返回插入这一行的主键的值。(特别注意使用条件:只能用于主键自动增长的表)

create proc Pr_AddVote
(
   @item varchar(50)
)
as
insert into votes(item ,votecount) values (@item,0)
return @@identity
go

这句竟然没效果,汗。

验证用户是否存在的存储过程

create proc JudgeUserName
@FullName nvarchar(50),
@returnValue int output
as
if exists (select Fullname from customers where
Fullname=@FullName)
set @returnValue = 1
else
set @returnValue = 0
go

判断用户名和密码是否正确的存储过程

--判断用户名和密码是否正确(返回列的做法)
Alter proc CustomerLogin
(
   @FullName nvarchar(50),
   @UserPassword nvarchar(50),
   @CustomerID int output  
)
as
select @CustomerID=CustomerID from Customers where  FullName=@FullName and UserPassword=@UserPassword   --过存在返回它的主键值。同时做以下更新
if @@Rowcount <1
select @CustomerID=0  --表示用户不存在
else
begin
update Customers set LastTimeLand=(getdate()),LandTime=LandTime+1 where FullName=@FullName
end
go