zoukankan      html  css  js  c++  java
  • 温故而知新--sql存储过程复习

    存储过程是已编译好的T-SQL语句的集合,可以随时调用,速度快,不易出错。但是写长了 确实是很难维护,在项目中我也不怎么喜欢使用。

    实例1   可以传递参数,普通参数和输出参数(output)

    create proc Newpro

    @testVarA int,

    @testVatB int,

    @testSum int Output

    as

    begin

    set @testSum=@testVarA+@testVarB

    end

    调用存储过程Newpro

    declare @testA int

    execute Newpro 100,200,@testA output

    print @testA

    实例2

    create proc testUser

    @testUserName varchar(30),

    @testPassWord varchar(30)

    as

    begin

    declare @testMsg varchar(100)

    if @testUserName='user1'

         begin

         if @testPassWord='123'

         set @testMsg='欢迎进入'

         else

         set @testMsg='对不起,密码错误'

         end

    else if @testUserName='user2'

         begin

          if @testPassWord='abc'

          set @testMsg='欢迎进入'

          else

          set @testMsg='对不起,密码错误'

         end

    else

          set @testMag='请输入正确的用户名'

    print @testMsg

    end

    调用存储过程testUser

    exec testUser 'user1','123'

  • 相关阅读:
    AD预测论文研读系列2
    hdu 5795
    sg函数的应用
    二分查找
    快速幂
    筛选法素数打表
    多校hdu-5775 Bubble sort(线段树)
    多校hdu5754(博弈)
    多校hdu5738 寻找
    多校hdu5726 线段树+预处理
  • 原文地址:https://www.cnblogs.com/tdws/p/4063006.html
Copyright © 2011-2022 走看看