Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-sqlserver > #1444

Needed to create a SQL script based on coloum in the domain table in a SystDB Database

Newsgroups comp.databases.ms-sqlserver
Date 2013-04-14 18:55 -0700
Message-ID <9ccc371d-d385-4b7f-82b0-a583350219d4@googlegroups.com> (permalink)
Subject Needed to create a SQL script based on coloum in the domain table in a SystDB Database
From Sonny <hairnhenna@gmail.com>

Show all headers | View raw


I have a system which has 200+ databases and needed to run the following script automatically on each one of them.
The 200 databases names can be found in the databasename coloum in the domain table in one of the databases which is the system database.
So if I run the following script i get all the databases that I need to run the scripts below on.

DEMOSYSTEM DB
select databasename from domain.

This gives me the names of the databases 
eg. 
DB1
DB2
DB3 etc etc.

The scripts then that I need to run on DB1, DB2, DB3 is as below

GO
CREATE USER [Master60SP] FOR LOGIN [Master60SP]
GO
ALTER USER [Master60SP] WITH DEFAULT_SCHEMA=[Master60SP]
GO
CREATE SCHEMA [Master60SP] AUTHORIZATION [Master60SP]
GO
EXEC sp_addrolemember N'db_datareader', N'Master60SP'
GO
EXEC sp_addrolemember N'MSDynamicsSL', N'Master60SP'

How can I create a script that will run the scripts as above on all the databases whose names are in the domain tables/Coloum name Databasename

Back to comp.databases.ms-sqlserver | Previous | NextNext in thread | Find similar


Thread

Needed to create a  SQL script based on coloum in the domain table in a  SystDB Database Sonny <hairnhenna@gmail.com> - 2013-04-14 18:55 -0700
  Re: Needed to create a SQL script based on coloum in the domain table in a SystDB Database Erland Sommarskog <esquel@sommarskog.se> - 2013-04-15 07:31 +0000

csiph-web