Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Copy entire SQL Database into another

Author  Topic 

c.vaibhav
Starting Member

26 Posts

Posted - 2010-03-24 : 16:32:59
Hi,

I want to create a database which will have all the tables and content of an existing database but with a different name.
I mean there already exist a database with name "ABC" but now I want to create another with the same content as of "ABC" but with a new name "DEF".

How can I do this using query?

Regards,
Vaibhav

DBA in the making
Aged Yak Warrior

638 Posts

Posted - 2010-03-24 : 16:59:48
You can do it with a backup/restore.

-- Create a new database backup
BACKUP DATABASE AdventureWorks TO DISK = 'D:\ADW.bak'
WITH INIT, STATS = 10
GO

-- Restore it to a different database name
RESTORE DATABASE AdventureWorks_2
FROM DISK = 'D:\ADW.bak'
WITH RECOVERY, STATS = 10,
MOVE 'AdventureWorks_Data' TO 'D:\SQLServer\MSSQL.1\MSSQL\Data\AdventureWorks_2_Data.mdf',
MOVE 'AdventureWorks_Log' TO 'D:\SQLServer\MSSQL.1\MSSQL\Data\AdventureWorks_2.ldf'
GO


There are 10 types of people in the world, those that understand binary, and those that don't.
Go to Top of Page

DBA in the making
Aged Yak Warrior

638 Posts

Posted - 2010-03-24 : 17:01:01
Don't forget to delete the backup file (in this case, 'D:\ADW.bak') when you're done with it.

There are 10 types of people in the world, those that understand binary, and those that don't.
Go to Top of Page
   

- Advertisement -