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

 

 

 

posted @ 2013-09-16 11:15  New~one  阅读(219)  评论(0编辑  收藏  举报