Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Create table in all databases

$
0
0

I'm trying to create a table and insert some data in all the databases through  package. Below are the steps .

1. Created variable user::database and set type as Object.

2. Created Exec sql task with query 'select database_id,name from sys.databases' and set resultset to variable user :::database.

3. Added For each loop container with ADO enumerator and set ADO object source variable to user::database. Added a new variable DBName with datatype=int32, added in Foreach loop container in variable mapping with index=0.

4. Added another exec sql task under for each loopcontainer with below script .

Under parameter mapping mapped User::dbname with Direction=Input,datatype=varchar,Parametername=@dbname,Parametersize=100

Declare @dbname varchar(100)
set @dbname=?
if exists (select name from sys.tables where name='Mytable') Drop table Mytable
go 
create table mytable (myid int,name varchar(100))
DECLARE @myid int
set @myid=0
While @myid<10
begin
Insert into mytable
values (@myid,'santhosh')
select @myid=@myid+1
end

Package gets exec successfully but the script operation is performed only in Master database. What may be the issue ?





SANTHOSH KUMAR



Viewing all articles
Browse latest Browse all 24688


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>