学习 SQL Server (7) :存储过程

------------------ 系统存储过程 -------------------
--微软定义好的,可以直接使用的存储过程,叫做系统存储过程
--system procedure 如:sp_xxx
exec sp_helpdb master

exec sp_bindrule

 

----------------- 自定义存储过程 -------------------
--由程序员定义的存储过程

--扩展存储过程

 


----================== 存储过程的创建 无参数 ===============---
--定义
create procedure pro
as
begin
declare @x int
set @x=1
while @x<10
begin
print @x
set @x=@x+1
end
end

--调用
exec pro

--删除存储过程
drop procedure pro2

--修改
alter procedure pro
as
begin
declare @x int
set @x=1
while @x<10
begin
print @x
set @x=@x+1
end
end

 


-------============ 存储过程的创建 有参数 ===============------------

--定义有参数 存储过程,实现查询出学生的成绩,按学生姓名模糊查询。以姓名关键字为参数 【重点】
create procedure por_select @sname varchar(20)
as
begin
select * from student where name like '%'+@sname+'%'
end

exec por_select '三'


--查询存储过程
exec sp_help por_select
exec sp_helptext por_select

 

作者还在学习中,发现错误的请在评论区留言。  如果有客友觉得文章还行的话,请点波推荐哦👍。 谢谢你们!!

posted @ 2020-06-19 15:04  JackeyLovelove  阅读(482)  评论(0编辑  收藏  举报
Live2D