zoukankan      html  css  js  c++  java
  • 在数据库中插入一行并且返回该行主键的值的做法(存储过程) 雨

    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

  • 相关阅读:
    react 在IE9下input标签使用e.target.value取值失败
    mingw-w64 about
    Cygwin .a 转为 .lib .dll
    windows terminal
    ssh key authentication
    sshd_config 2
    sshd_config
    bash sudo redirect multiple lines to file
    计算几何
    vs cli
  • 原文地址:https://www.cnblogs.com/manage/p/1957543.html
Copyright © 2011-2022 走看看