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

来源:互联网 发布:电信4g网络好用吗 编辑:程序博客网 时间:2024/06/09 14:02

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


原创粉丝点击