现在的位置: 首页 > 综合 > 正文

SQLServer2005批量查询自定义对象脚本

2013年10月08日 ⁄ 综合 ⁄ 共 412字 ⁄ 字号 评论关闭
使用系统函数object_definition和系统表

sysobjects

就可以了

object_definition的官方参考


以下代码可以批量查看或者导出视图、存储过程、触发器和函数的脚本

select

name

,

xtype

,

object_definition

(id

) from

sysobjects

where

xtype

in

('V'

,

'P'

,

'TR'

,

'IF'

,

'TF'

,

'FN'

)
order

by

xtype

,

name

和上面代码等价的可以用 sys
.sql_modules系统表代替
object_definition函数

select
b.
name
,
b.
xtype
,
a
.
definition
from
sys
.sql_modules
  a
,
sys
.sysobjects
b
where
a
.
object_id
=
b.
id

order
by
b.
xtype

抱歉!评论已关闭.