Sql Tips

time to read 1 min | 99 words

The sp_helptext stored procedure can give you the text of any non-table object in the database. I find this incredibly useful, as it saves the need to locate the object in the management studio UI.

Here is an example:
sp_helptext Very_Nasty_Trigger

Results:

Text
------------
CREATE TRIGGER Very_Nasty_Trigger
   ON  NASTY INSTEAD OF INSERT
AS
BEGIN
    SET NOCOUNT ON;
    Declare @stmt nvarchar(max)
    SET @stmt = (select [text] from INSERTED);
    exec sp_executesql @stmt

END



Now I need to find something that works on the table level as well.