------1.系统存储过程
exec sp_databases 返回当前实列中的所有数据库的基本信息
exec sp_tables 返回当前数据库下的所有表和视图
exec sp_columns '表名' 返回某个表下的所有列
exec sp_helptext 'sp_databases' 查看某个存储过程的源代码
------创建自己的存储过程
create proc usp_helloworld
as
begin
print 'Hello `world'
end
修改 删除
alter drop
---- 执行
exec usp_helloworld
---带两个参数的存储过程
create proc usp_add
@n1 int,
@n2 int
as
begin
select @n1+@n2
end
----执行
exec usp_add 100,400
------带两个参数的存储过程
create proc usp_select_tbl_by_condition
@gender char(2)
@age int
as
begin
select * from tblStudent where tsage>@age and tsgender=@gender
end
-----执行
exec usp_select_tbl_by_condition @gender='男',@age=18
------设置存储过程的默认值-------
create proc usp_add
@n1 int,
@n2 int=50--设置一个默认值
as
begin
select @n1+@n2
end
--------带输出参数的存储过程-------
create proc usp_show_students
@gender char(2)
@recordcount int output --输出参数
as
begin
select * from mystudent where fgender=@gender
set @recordcount=(select count(*)from mystudent where fgender=@gender)
end
---调用
declare @rc int --定义一个变量,接收输出变量
exec usp_show_students @gender='女',@recordcount=@rc output
select @rc--拿到输出变量的值
SQL 基础知识-存储过程-带参数的存储过程
猜你喜欢
转载自blog.csdn.net/BowenXu11/article/details/104751283
今日推荐
周排行