系统存储过程sql server

本文详细介绍了SQL中的存储过程,包括获取数据库信息、表信息、列信息的系统存储过程,以及如何创建、修改、删除存储过程。还展示了如何在存储过程中使用参数和输出参数进行数据操作,以及实现分页查询。内容涵盖了数据库管理和开发的基础知识。
摘要由CSDN通过智能技术生成

-----------系统存储过程------------
–1.返回当前实例中的所有的数据库的信息,列出服务器上所有的数据库
exec sp_databases
–2.返回当前数据库下的所有的表,返回单前环境下可查询的对象的列表
exec sp_tables
–3.返回某张表下的所有的列,返回某个表列的信息
exec sp_columns ‘test’
–4.更改数据库的名称
exec sp_helpdb
–5.更改数据库名称
exec sp_renamedb
–6.查看某个表的约束
exec sp_help
–7.查看某个表的约束

–8.查看某个存储过程的源代码
exec sp_helptext ‘Pro_cw_jk_sh_fyhz’

-----------创建自已的存储过程---------------
create proc usp_helloworld
as
begin
print ‘hello world’
end

exec usp_helloworld

drop proc usp_select_student //删除存储过程
alter proc usp_select_student //修改存储过程
create proc usp_select_student

alter proc usp_select_student
as
begin
select * from dbo.student where name = ‘zhang’
end

—调用存储过程—
exec usp_select_student

–创建一个带两个参数的存储过程
create proc usp_add
@n1 int,
@n2 int
as
begin
select @n1+@n2
end
–调用存储过程
exec usp_add 100,200


alter proc usp_select_tblstudent_by_condition
@gende varchar(20),
@salary varchar(20)
as
begin
select * from dbo.student where salary >= @salary or grade = @gende
end

exec usp_select_tblstudent_by_condition 1500,‘%’

-------带出参数的存储过程-------
–当在存储过程当中需要返回多个值的时候,就可以使用输出参数来返回这些值
create proc usp_show
@gender varchar(20),
@record int output --输出参数
as
begin
select * from student where grade = @gender
–把查询语句查询到的记录的条数赋值给变量@record
select @record =(select count(*) from student where grade = @gender)
end

—调用存储过程:
–调用带有输出参数的储存过程的时候,需要定义变量,将变量传递给输出参数,
–在存储过程中使用的输出参数,其实就是你传递进来的变量;

declare @tc int;
exec usp_show @gender = ‘A’,@record = @tc output
print @tc

-----使用存储过程编写一个分页查询
set nocount off
select * from student

create proc usp_getstudent_databypage
@pagesiez int=7, --每页记录条数
@pageindex int=1, --当前要查看第几页的记录
@recordcount int output --总的记录的条数
@pagecount int output --总的页数
as
begin
–1.编写查询语句,把用户要的数据查询出来
select *
from (select *,rn=ROW_NUMBER() over(order by asc) from student) as “t”
where

end

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

曾凡宇先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值