create proc userlogin(@usermame varchar(20),@userpassward varchar(20),@userroleid int,@returninfo varchar(50) output) as begin if not exists(select 1 from tb_userinfo where username=@username and userroleid=@userroleid) begin set @returninfo='用户名不存在' end else if not exists(select 1 from tb_userinfo where username=@username and userroleid=@userroleid and userpassward=@userpassward) begin set @returninfo="密码错" end else begin insert into tb_userloginInfo ..... set @returninfo="成功" end end
我给大家看下我创建的存储过程来验证以登录框中的多个角色的功能。 希望各位大侠们们看看还有什么问题。create proc loginCheck(@userName varchar(16),@userPassword varchar(6),@No int output) as begin if exists (select 1 from personalUserInfo where userName = @userName and userPassword = @userPassword) begin set @No = 1 end else if exists (select 1 from enterpriseUserInfo where enterpUserName =@userName and enterpUserPassword = @userPassword ) begin set @No=1 end else begin set @No=0 end end
create proc loginCheck(@userName varchar(16),@userPassword varchar(6),@No int output) as begin if exists (select 1 from personalUserInfo where userName = @userName and userPassword = @userPassword) begin set @No = 1 end else if exists (select 1 from enterpriseUserInfo where enterpUserName =@userName and enterpUserPassword = @userPassword ) begin set @No=2 end else begin set @No=0 end end 像上面的哈,我想可以用存储过程实现多个表的一次验证功能(但是这需要保证多个表数据的唯一性),同时要求使用设置不同值(@NO)来不同表的查询过程。在写代码的时候通过判断查询判断的值就行了,这样在前面代码就会简洁很多,全部由数据库的存储过程去验证数据的有效性。
as
begin
if not exists(select 1 from tb_userinfo where username=@username and userroleid=@userroleid)
begin
set @returninfo='用户名不存在'
end
else if not exists(select 1 from tb_userinfo where username=@username and userroleid=@userroleid and userpassward=@userpassward)
begin
set @returninfo="密码错"
end
else
begin
insert into tb_userloginInfo .....
set @returninfo="成功"
end
end
其实和存储过程使用的道理是一样的,只是存储过程这个过程由数据库完成,后面有人为编码完成。两个其实是一样。
希望各位大侠们们看看还有什么问题。create proc loginCheck(@userName varchar(16),@userPassword varchar(6),@No int output)
as
begin
if exists (select 1 from personalUserInfo where userName = @userName and userPassword = @userPassword)
begin
set @No = 1
end
else if exists (select 1 from enterpriseUserInfo where enterpUserName =@userName and enterpUserPassword = @userPassword )
begin
set @No=1
end
else
begin
set @No=0
end
end
create proc loginCheck(@userName varchar(16),@userPassword varchar(6),@No int output)
as
begin
if exists (select 1 from personalUserInfo where userName = @userName and userPassword = @userPassword)
begin
set @No = 1
end
else if exists (select 1 from enterpriseUserInfo where enterpUserName =@userName and enterpUserPassword = @userPassword )
begin
set @No=2
end
else
begin
set @No=0
end
end
像上面的哈,我想可以用存储过程实现多个表的一次验证功能(但是这需要保证多个表数据的唯一性),同时要求使用设置不同值(@NO)来不同表的查询过程。在写代码的时候通过判断查询判断的值就行了,这样在前面代码就会简洁很多,全部由数据库的存储过程去验证数据的有效性。