Discussion:
I have a trigger that I need to run on all application databases that are in the domain.database(Table.Coloum) of a SLSYSTEM Database, Dont want to do it manually
(too old to reply)
Sammy Singh
2013-04-16 19:43:15 UTC
Permalink
I have a trigger that I need to run on all application databases that are in the domain.database(Table.Coloum) of a SLSYSTEM Database
So if I do a select databasename from domain on the system database I get the 250+ Application database name. So I want to run a Trigger SQL Script on each of the 250+ application databases.
Is there some way I can create a script to do this for all the databases in the domain.databasename of the SLSYSTEM database.

Thanks so much in advance.
Erland Sommarskog
2013-04-16 20:52:36 UTC
Permalink
Post by Sammy Singh
I have a trigger that I need to run on all application databases that
are in the domain.database(Table.Coloum) of a SLSYSTEM Database So if I
do a select databasename from domain on the system database I get the
250+ Application database name. So I want to run a Trigger SQL Script on
each of the 250+ application databases. Is there some way I can create a
script to do this for all the databases in the domain.databasename of
the SLSYSTEM database.
The easiest would be to write a small C# program that accepts a file
name as inparameter, reads that file into a varibale and then retrieves the
database name from that domain table, and then for every database runs:

cmd.CommandText = "USE " + dbname
cmd.ExecuteNonQuery();
cmd.CommandText = file_contents;
cmd.ExecuteNonQuery();
--
Erland Sommarskog, SQL Server MVP, ***@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
Loading...