Page 1 of 1

How to install an existing SQL-Server database?

Posted: Tue Oct 16, 2007 9:28 am
by folo77
Hello,

I'm using IA V6.22 and I want my Setup to install an existing SQL-Server Database (mdf/ldf-file are present) to a local SQL-Server 2005 database system. I have already managed to create a new database by integrating a new (empty) MS SQL Script and checking "Create database if absent". Then I tried to generate a SQL-Script that contains the whole database layout (tables...) and the whole content, but that seems a little bit too complex and inefficient to me.

Is there an easier way to add an existing SQL-Server Database to a (local) SQL-Server using the IA Installer, e.g. by copying and somehow adding the mdf/ldf-files to the (locally installed) SQL-Server instead of transforming the whole database into a script?

Thanks in advance...

Posted: Wed Oct 17, 2007 11:48 am
by Alex_Ronquillo
You can restore your DB from the mdf/ldf files with a restore script. Here is an example:

Code: Select all

RESTORE DATABASE [DBName] FROM DISK = '$SUPPORTDIR$DBName.BAK' WITH REPLACE, MOVE 'DBName_Data' TO '$Path$\\DATA\\DBName.MDF', MOVE 'DBName_Log' TO '$Path$\\DATA\\DBName.LDF'

Posted: Thu Oct 18, 2007 4:58 am
by folo77
Thank you! That was exactly what I needed.

I created the DBName.BAK file with the backup function of the SQL Server Management Console. Then I added it to the Support Files in IA and completed the script as follows, so that I don't overwrite any existing database:

Code: Select all

 IF NOT EXISTS(SELECT * FROM sys.databases where name = 'DBName')
RESTORE DATABASE [DBName] FROM DISK = '$SUPPORTDIR$DBName.BAK' WITH REPLACE, MOVE 'DBName_Data' TO '$Path$\\DATA\\DBName.MDF', MOVE 'DBName_Log' TO '$Path$\\DATA\\DBName.LDF'