存储过程基础知识汇总

来源:互联网 发布:dt大数据 编辑:程序博客网 时间:2024/05/17 22:32

--查询所有存储过程
select * from sys.objects where type = 'P';
--修改存储过程
alter proc proc_get_student
as
select * from student;
--调用、执行存储过程
exec proc_get_student;
--------------------------------
--创建存储过程
if (exists (select * from sys.objects where name = 'proc_get_student'))
drop proc proc_get_student
go
create proc proc_get_student
as
select * from 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;
-------------------------------------

--带通配符参数存储过程
if (object_id('proc_findStudentByName', 'P') is not null)
drop proc proc_findStudentByName
go
create proc proc_findStudentByName(@name varchar(20) = '%j%', @nextName varchar(20) = '%')
as
select * from student where name like @name and name like @nextName;
go

exec proc_findStudentByName;
exec proc_findStudentByName '%o%', 't%';




原创粉丝点击