简单的sql登录和注册存储过程

来源:互联网 发布:越南翻译软件 编辑:程序博客网 时间:2024/06/03 12:29

 首先我建好了一张用户表表中有俩个字段 一个是账号,一个是密码当然这里我写的知识简单的登录很注册,

表明 users 用户表

字段 accountnum  varchar(50) --表示账号

        password     varchar(50) --表示密码

 

登录存储过程

create proc use_login

(

@accountnum varchar(50),

@password varchar(50),

@message  varchar(50) output

as

  if exists(select * from users where accountnum=@accountnum and  password=@password)

   set @message='登录成功'

 else  if  exists(select * from users where accountnum=@accountnum )

   set @message='密码错误'

 else if exists(select * from users where password=@password)

  set @message='用户名错误'

else

  set @message='用户名和密码都错误'

 

declare @msg as varchar(50)

exec use_login 'text','text',@msg output

print @msg

 

注册存储过程

create proc use_registration

(

@accountnum varchar(50),

@password varchar(50),

@message  varchar(50) output

)

as

  if exists(select * from users where accountnum=@accountnum)

   set @message='该用户已经存在'

 else

    begin

     insert into users values(@accountnum,@password)

     set @message='恭喜您,可以注册该用户'

  end 

 

  declare  @msg as varchar(50)

 exec use_registration 'text','text',@msg output

print @msg

 

上面再执行存储过程的时候 要打印所要显示出来的信息用的是print 也可以用select