• sql server 存储过程


     1. 创建存储过程:(带参数的存储过程)

     create procedure ST_admin_009
    @account_1 char(50)
    as
     select * from admin where account=@account_1
    go
    exec ST_admin_009 'light'

    2. 删除存储过程:

     drop procedure ST_admin_008

    3. 修改存储过程:

    4. 查看存储过程 
       存储过程被创建之后,它的名字就存储在系统表sysobjects中,它的源代码存放在系统表syscomments中。可以使用使用企业管理器或系统存储过程来查看用户创建的存储过程

       sp_helptext:用于显示存储过程的源代码

    5. 列子:

    在Northwind数据库中,创建一个带查询参数的存储过程,
    要求在输入一个定购金额总额@total时,查询超出该值的所
    有产品的相关信息,包括产品名称和供应商名称、单位数量、
    单价、以及该产品的定购金额总额,并通过一个输出参数返回
    满足查询条件的产品数

    IF exists (select * from SysObjects where name='more_than_total' and type='p')
       drop procedure more_than_total
    go
    CREATE PROCEDURE More_Than_Total
            @total money = 0
    AS
    Declare @amount smallint
    BEGIN
            select distinct
               P.productName,
               S.contactName,
               P.UnitPrice
               
        from Products P inner join [order Details] O 
             on p.productID=o.productID inner join suppliers s 
             on p.supplierID=s.SupplierID
        where O.productID in
        (select productID 
         from   [order Details] 
         group by productId
         having sum(quantity*unitprice)>@total
        )
    END
    GO

  • 相关阅读:
    黄聪:数据库基础
    黄聪:(C#)利用反射动态调用类成员[转载]
    黄聪:SQL 2005 全文索引
    黄聪:自动化测试的7个步骤
    黄聪:队列Queue笔记
    黄聪:VMware三种网络连接方式的概念
    Nginx 模块细节详探
    munin因为plugin而亮
    Zookeeper简介
    Munin进阶使用
  • 原文地址:https://www.cnblogs.com/a892647300/p/3323912.html
Copyright © 2020-2023  润新知