This example shows a SELECT statement that generates a script to dump the sp_helptext output for all stored procedures and functions. Run it with the output set to text in SQL Server Management Studio; copy the results to a new query window and execute the script, again with output to text. The "SET NOCOUNT" statements are included so that there won't be an extra row like this: (856 row(s) affected) at the end of the generated script, but you can omit them and just remember to leave it out.
This technique can be used whenever you have a repeating process that doesn't lend itself to a set-oriented query (like running a stored procedure against selected values from a table).
SET NOCOUNT ON GO SELECT 'sp_helptext ' + [SPECIFIC_NAME] + CHAR(13) + CHAR(10) + 'GO' + CHAR(13) + CHAR(10) FROM INFORMATION_SCHEMA.ROUTINES WHERE [ROUTINE_TYPE] = 'PROCEDURE' OR [ROUTINE_TYPE] = 'FUNCTION' ORDER BY [ROUTINE_NAME] GO SET NOCOUNT OFF GO
The generated script looks like this:
-------------------------------------------------------------------------------------------------------------------------------------------------- sp_helptext BAEAccountPendingDelete GO sp_helptext BAEAccountPendingGetAll GO sp_helptext BAEAccountPendingInsert GO etc.
there's no INFORMATION_SCHEMA.TRIGGERS...
...so use this query if you're interested in viewing all triggers:
SELECT 'sp_helptext ' + [name]
+ CHAR(13) + CHAR(10) + 'GO' + CHAR(13) + CHAR(10)
FROM sys.triggers
ORDER BY [name]