sql server 的存储过程

存储过程说白了就是一堆 SQL 的合并。中间加了点逻辑控制。

存储过程运行流程

 

创建不带参数存储过程

--创建存储过程

if (exists (select * from sys.objects where name = 'proc_get_student'))
    drop proc proc_get_student

  

create proc proc_get_student
as
    select * from student;

  结果:

--调用、执行存储过程

exec proc_get_student;

  查询结果:

 

 

带参存储过程

if (object_id('proc_find_stu', 'P') is not null)
    drop proc proc_find_stu
go
create proc proc_find_stu(@startId int, @endId int)
as
    select * from student where id between @startId and @endId
go

exec proc_find_stu 2, 4;

  执行结果:

 

 

 

2018-05-08   15:50:54

 

posted @ 2018-05-08 15:51  1点  阅读(200)  评论(0编辑  收藏  举报