SQL 存储过程


1.将复杂的sql语句进行封装,可以用来增删改查


2.创建

create proc 名字
@num1 int, --变量
@num2 int --变量
@count int output --变量,返回值
as
begin
select @num1+@num2 --执行的函数 sql语句
end

 

3.修改
  alter proc


4.使用

--第一种方式
exec usp_numberAdd @num1=10,@num2=20
--第二种方式
declare @n1 int=21,@n2 int=32
exec usp_numberAdd @num1=@n1,@num2=@n2
--第三种方式
exec usp_numberAdd 30,20

 

5.示例(分页)

create proc usp_fenye
@ye int,
@dijiye int,
@sumPage int output
as
begin    
    set @sumPage=(CEILING((select count(*) from student)*1.0/@ye))
    select * from 
    (select *,序号=ROW_NUMBER()over(order by tsid) from student) as newstudent
    where 序号 between (@dijiye-1)*@ye+1 and @dijiye*@ye
end

declare @sum int
exec usp_fenye 2,3,@sum output
select @sum

 

posted @ 2017-08-02 16:11  风儿_VIP  阅读(201)  评论(0编辑  收藏  举报