Use mastergoif object_id ('SP _ SQL ') is not nulldrop proc sp_sqlgo /********************************** **************************************** **************************************** * ************************************ Organizer: chinese style (Roy) Date: 2008.01.01 *************************************** **************************************** **************************************** * *****************************/create pro C [DBO]. [sp_ SQL] (@ objectname sysname) asset nocount on; declare @ print nvarchar (max) ---- @ print use nvarcharif exists (select 1 from syscomments where id = object_id (@ objectname) and encrypted = 1) Begin print n' pairs are encrypted! 'Returnendif coalesce (object_id (@ objectname, n'p'), object_id (@ objectname, n'fn '), object_id (@ objectname, n'if '), object_id (@ objectname, n'tf'), object_id (@ objectname, n'tr'), object_id (@ objectname, n'v ')) is nullbeginprint n' object only records the number of function, stored process, producer, and response! 'Return endprint 'use' + db_name () print 'go 'print 'If object_id (' + quotename (case when charindex (']', @ objectname) = 0 then' ['+ Replace (rtrim (@ objectname ),'. ',']. [') +'] 'else @ objectname end, ''') + ') is not null 'print char (9) + 'drop' + casewhen object_id (@ objectname, N 'P') is not null then' procedure 'when coalesce (object_id (@ objectname, n'fn '), object_id (@ objectname, n'if '), object_id (@ objectname, n'tf') is not null then 'function' when object_id (@ objectname, n'tr ') is not null then 'trigger' else 'view' end + case when charindex (']', @ objectname) = 0 then' ['+ Replace (rtrim (@ objectname ), '. ',']. [') +'] 'else @ objectname endprint 'Go' declare @ t table (COL nvarchar (max) insert @ t select object_definition (object_id (@ objectname )) + char (13) + char (10) While (select max (COL) from @ t)> ''ininselect top 1 @ print = left (COL, charindex (char (13) + char (10), col)-1) from @ tprint @ printupdate @ t set Col = stuff (COL, 1, charindex (char (13) + char (10 ), COL) + 1, '') endprint 'go 'usage: Use test -- specify the number of bytes consumed exec sp_ SQL 'SP _ SQL' -- specify the object