Question : Copy MSSQL DB to another DB on same server

I would like to copy database A to database B at a specific time.  I want to overwrite whatever data is in database B at the time.  Both DB's exist on the same server.  I'm running MS SQL 2005

Answer : Copy MSSQL DB to another DB on same server

I forgot,  there is even a script-button in management studio.  You can enter your options for your backup in dthe GUI and then script it without having to execute it.

Important is the COPY_ONLY this will prevent that with a recovery model FULL your next transactionlog refers to this backup but still to the backup of the maintenance plan

Made a small example
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
-- Backup database 'dbA'
BACKUP DATABASE [dbA] 
TO  DISK = N'C:\MSSQL\Backup\dbB.Comp090525220021.BAK'  
WITH NOFORMAT, NOINIT, 
 NAME = N'dbA-Full Database Backup'
, SKIP, NOREWIND, NOUNLOAD,  STATS = 10
,  COPY_ONLY -- don't interfere with backup-schema
GO

-- Restore database 'DbA' from previously taken backup
-- command invalidated to prevent accidents
--RESTORE DATABASE [dbA] 
RE   STORE DATABASE [dbA] 
FROM  DISK = N'C:\MSSQL\Backup\dbB.Comp090525220021.BAK'  
WITH  FILE = 1,  NOUNLOAD,  REPLACE,  STATS = 10
GO

-- Restore database 'dbB' from previously taken backup of database 'dbA'
-- command invalidated to prevent accidents
--RESTORE DATABASE [dbB] 
RE   STORE DATABASE [dbB] 
FROM  DISK = N'C:\MSSQL\Backup\dbB.Comp090525220021.BAK' 
WITH  FILE = 1,  
MOVE N'db_Data' TO N'C:\mssql\DATA\dbB.mdf',  
MOVE N'db_Log' TO N'C:\mssql\DATA\dbB_1.ldf',  NOUNLOAD,  REPLACE,  STATS = 10
GO
Random Solutions  
 
programming4us programming4us