Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script Just Triggers, SQL 2005

Status
Not open for further replies.

yeagly21

Programmer
Dec 11, 2003
23
US
Does anyone know how to script just triggers out of a SQL 2005 database?
 
This should give you some ideas. You will just need to change your criteria to script the triggers rather than the procs. Not sure what the type is off hand, but should be easy enough to find out.

thread183-1354984

Hope this helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
In 2005 there are 3 levels of triggers, table, database and server. Which level do you want to script?

- Paul
- If at first you don't succeed, find out if the loser gets anything.
 
Paul -

I am looking to script the Table triggers. Sorry I should have included that info.
 
Yeagly21 - did you look at the thread that I posted?

Ignorance of certain subjects is a great part of wisdom
 
I am looking at it right now to see if I can adjust the script to give me that results i am looking for.
 
This is what I ended up creating to give me the result set. I ran it in Management Studio and ran the query to text. Its not the most efficient method so if anyone has a better way to do this that would be great to know.

Code:
DECLARE @ProcDefinition VARCHAR(MAX),@ProcName VARCHAR(8000)
Declare Load_curs cursor for

select  name as 'Trigger' as 'Name'
from sysobjects
where xtype = 'TR'

open Load_curs
fetch next from Load_curs into @ProcName 

while (@@fetch_status=0)
begin

PRINT 'SET ANSI_NULLS ON '
PRINT 'GO'
PRINT 'SET QUOTED_IDENTIFIER ON'
PRINT 'GO'
 
EXEC  sp_HelpText @ProcName 

PRINT 'GO'

fetch next from Load_curs into @ProcName
end
close Load_curs
deallocate Load_curs

-Yeagly21
 
sp_HelpText has weird problems with white space, at least in my experience. Be wary.

[COLOR=#aa88aa black]Cum catapultae proscriptae erunt tum soli proscript catapultas habebunt.[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top