Dynamic creation on DataBase
Hi,
I have a reqirement where in i need to create a Database dynamically in SSIS, Database name is given in table.


Regards,
Miranda
July 31st, 2015 11:13am

Are you looking towards the steps to create Dynamic Database in SSID then Google Out Your Query you will definitely find various blogs. like sql-developers.blogspot.in/2010/07/dynamic-database-connection-using-ssis.html

mssqltips.com/sqlservertip/1437/dynamically-build-connection-objects-for-ms-access-databases-in-ssis/

Free Windows Admin Tool Kit Click here and download it now
July 31st, 2015 11:59am

Hi ,

No i could not find .

i need to create Database dynamically  by passing the Database name as variable .

Regards,

Miranda.

July 31st, 2015 12:20pm

Hi mirandaroopa,

Please try the below query

DECLARE @DataFile NVARCHAR(1024)
DECLARE @LogFile NVARCHAR(1024)
EXEC master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE'
	,N'Software\Microsoft\MSSQLServer\MSSQLServer'
	,N'DefaultData'
	,@DataFile OUTPUT
EXEC master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE'
	,N'Software\Microsoft\MSSQLServer\MSSQLServer'
	,N'DefaultLog'
	,@LogFile OUTPUT
SET @DataFile = @DataFile + '\TESTDB_dat1.mdf'
SET @LogFile = @LogFile + '\TESTDB_log1.ldf'
DECLARE @sql NVARCHAR(max)
SET @sql = 'CREATE DATABASE [TESTDB]
 CONTAINMENT = NONE
 ON  PRIMARY 
  (NAME = N''TEST_dat1'', FILENAME = N' + QUOTENAME(@DataFile, '''') + ', SIZE = 4096KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB)
 LOG ON 
( NAME = N''TEST_log1'', FILENAME =  N' + QUOTENAME(@LogFile, '''') + ', SIZE = 1280KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)'
EXECUTE sp_executesql @sql

instead of 

TESTDB please append your variable
Free Windows Admin Tool Kit Click here and download it now
July 31st, 2015 1:02pm

Hi,

Is there any way to create database using execute sql task and  by passing database name as variable ?

Regards,

Miranda

August 3rd, 2015 1:36am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics