SQL Server 2005 batch query custom object script


Official reference of object definition

The following code can batch view or export scripts for views, stored procedures, triggers, and functions

Copy codeThe code is as follows:
select name , xtype , object_definition (id ) from sysobjects
where xtype in (‘V’ , ‘P’ , ‘TR’ , ‘IF’ , ‘TF’ , ‘FN’ )
order by xtype , name

Equivalent to the above code, sys. SQL modules system table can be used instead of object definition function

Copy codeThe code is as follows:
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