读书人

Sql Server 施用系统存储过程 及 自定

发布时间: 2012-11-15 15:16:15 作者: rapoo

Sql Server 使用系统存储过程 及 自定义存储过程 “usp_Helloworld”

Sql Server系统存储过程
--是放在系统数据库 master 中的--可编程性---存储过错--系统存储过程中

exec sp_databases

----sp_databases的 内部 代码
select
DATABASE_NAME = db_name(s_mf.database_id),
DATABASE_SIZE = convert(int,
case -- more than 2TB(maxint) worth of pages (by 8K each) can not fit an int...
when convert(bigint, sum(s_mf.size)) >= 268435456
then null
else sum(s_mf.size)*8 -- Convert from 8192 byte pages to Kb
end),
REMARKS = convert(varchar(254),null)
from
sys.master_files s_mf
where
s_mf.state = 0 and -- ONLINE
has_dbaccess(db_name(s_mf.database_id)) = 1 -- Only look at databases to which we have access
group by s_mf.database_id
order by 1


---使用 sp_helptext 来显示一个 存储过程 中的 代码 。
exec sp_helptext sp_databases
exec sp_helptext sp_helptext

--给数据库重命名:

exec sp_renamedb 'Test','Test123'


--查询当前数据库中有多少个表

exec sp_tables


--查询当前数据库中的列信息

exec sp_columns 'Student'


自定义存储过程 “usp_Helloworld”并使用。实现输出hello world!

create proc usp_Helloworld
as
begin
print 'hello world!'
end

exec usp_Helloworld


读书人网 >SQL Server

热点推荐