Tuesday, March 20, 2012

Script only triggers in a database

Is there a way to script only the triggers in
a database?1. Right Click on the database name and select All Tasks and underneth that select Generate SQL Script. You will be presented with Generate SQL Scripts dialog box
2. In the General Tab Click 'Show All' button. Then select 'All Tables' check box
3. In the formatting Tab of the dialog box, delete everything 'Script template' text area
4. In the Options tab, under table scripting options check 'Script triggers' box
The main trick is to delete everything in the Formatting tab of the dialog box.|||Using Enterprise Manager you can select a database, right click and choose
All Tasks>Generate SQL Script. Then select Show All and check the All Tables
box. Next choose the Formatting Tab and uncheck all boxes. On the Options
tab, check the Script Triggers checkbox in the Table Scripting options
section. This should now generate the script for all the triggers. You can
also use SQLDMO in a VBScript file e.g.
Set oSQL = WScript.CreateObject("SQLDMO.SQLServer")
oSQL.Name = "(local)"
oSQL.LoginSecure = True
oSQL.LoginTimeout = 10
oSQL.Connect
Set oTransfer = WScript.CreateObject("SQLDMO.Transfer")
oTransfer.CopyAllTriggers = True
Set oDB = oSQL.Databases("pubs")
oDB.ScriptTransfer oTransfer,2,"c:\pubs_triggers.sql"
oSQL.DisConnect
Set oTransfer = Nothing
Set oSQL = Nothing
HTH
Jasper Smith (SQL Server MVP)
I support PASS - the definitive, global
community for SQL Server professionals -
http://www.sqlpass.org
"Phil396" <anonymous@.discussions.microsoft.com> wrote in message
news:16e8f01c420b5$0dddb6e0$a001280a@.phx.gbl...
> Is there a way to script only the triggers in
> a database?

No comments:

Post a Comment