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'

  • 相关阅读:
    一个好的技术管理人员需要知道的几件事
    团队必经的五个阶段以及好团队的七个特征
    作为CTO如何做技术升级
    技术领导画像
    TF-IDF原理
    KNN和K-Means的区别
    图数据库入门
    Hbase和Hive的异同
    谈谈机器学习面试
    关于领导力的理解
  • 原文地址:https://www.cnblogs.com/tdws/p/4063006.html
Copyright © 2011-2022 走看看