遍历技巧集

--遍历服务器中所有数据库名称

select a.name

from master..sysdatabases a
where a.dbid>=7 

------------------------------------------------------------------------------------------------

--遍历数据库中的所有存储过程,并获得其参数个数、类型、长度

select
    c.[name] sp_name, --存储过程名称
    a.[name] pa_name, --参数名称
    b.[name] pa_type, --参数类型
    a.[length] pa_len --参数长度
from
    syscolumns a , systypes b , sysobjects c
where
    a.xtype=b.xtype and a.id=c.id
    and c.xtype='p' and c.category=0
order by
    sp_name

--c.category=0 也可改为c.status>=0 表示用户定义的储存过程
--category:用于发布、约束和标识
--status:保留,内部使用。Base_schema_ver统计的版本号

------------------------------------------------------------------------------------------------

--遍历数据库中的所有触发器名称

select a.name as tr_name
from sysobjects a
where a.xtype='tr' and a.category=0

------------------------------------------------------------------------------------------------

--遍历数据库中的所有函数,并获得其参数个数、类型、长度
select
    f_name=c.[name],       --函数名称
    pa_name=case a.[name] when '' then 'returns' else a.[name] end, --参数名称
    pa_type=b.[name],       --参数类型
    pa_len=a.[length]       --参数长度
from
    syscolumns a , systypes b , sysobjects c
where
    a.xtype=b.xtype and a.id=c.id
    and c.xtype in (N'FN', N'IF', N'TF') and c.category=0
order by
    f_name

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值