Hi,
 I'd like to generate a script for only all the triggers in my database, but
 not the Tables.
 When I use the Generate script funtion in Enterprise manager, I can't enable
 the OK unless all tables or all views have been enabled on the General tab.
 Is there a way to save only all triggers to a script?
 Thanks very much for any help here
 AntAnt
For SQL Server 2000
 Dim sql As Object
 Dim db As Object
 Dim objTrigger As Object
 Dim intOptions As Long
 Dim genObj
 Set sql = CreateObject("SQLDMO.SQLServer")
 Set db = CreateObject("SQLDMO.Database")
 Set objTrigger = CreateObject("SQLDMO.Trigger")
 Const sDrops As Integer = 1
 Const sIncludeHeaders As Long = 131072
 Const sDefault As Integer = 4
 Const sAppendToFile As Integer = 256
 Const sBindings As Integer = 128
 ' Connect to local server
 sql.Connect "(local)", strLogin, strPwd
 Set db = sql.Databases(strDataBase, "dbo")
 ' Script Tables and Triggers, ignoring system
 ' tables and system generated triggers
 For Each genObj In db.Tables
 If genObj.SystemObject = False Then
 For Each objTrigger In genObj.Triggers
 If objTrigger.SystemObject = False Then
 objTrigger.Script intOptions, StrFilePath
 End If
 Next
 End If
 Next
End Sub
Save the module as MyModule.
To call the procedure, open the Immediate window, type the following line,
and then press ENTER:Call
ScriptDB("UserName","Password","DatabaseName","C:\MyResults.SQL")
Call ScriptDB("UserName","Password","DatabaseName","C:\MyResults.SQL")
For SQL Server 2005
http://dimantdatabasesolutions.blogspot.com/2007/06/triggers-definition.html
"Ant" <Ant@.discussions.microsoft.com> wrote in message
news:EFC9BFB2-6E17-4493-BACC-ECCF8ECB2B38@.microsoft.com...
> Hi,
> I'd like to generate a script for only all the triggers in my database,
> but
> not the Tables.
> When I use the Generate script funtion in Enterprise manager, I can't
> enable
> the OK unless all tables or all views have been enabled on the General
> tab.
> Is there a way to save only all triggers to a script?
> Thanks very much for any help here
> Ant
 
No comments:
Post a Comment