This T-SQL script is like copy A database paste to another database B in SQL Server . My SQL Server version is 2014, haven’t run another version. /*declare*/ DECLARE @path varchar(100)='E:\SQL_DATA\BACKUP\'; DECLARE @backfile varchar(100)=@path+'SourceDB.baktmp'; /*backup*/ BACKUP DATABASE [SourceDB] TO DISK = @backfile WITH NOFORMAT , NOINIT , NAME = N'SourceDB-Full Database Backup' , SKIP, NOREWIND, NOUNLOAD, STATS = 10 ; /*import*/ ALTER DATABASE [TargetDB] SET SINGLE_USER WITH ROLLBACK IMMEDIATE RESTORE DATABASE [TargetDB] FROM DISK = @backfile WITH FILE = 1 , MOVE N'TargetDB' TO N'E:\SQL_DATA\TargetDB.mdf' , MOVE N'TargetDB_log' TO N'E:\SQL_DATA\TargetDB_log.ldf' , NOUNLOAD, REPLACE, STATS = 5 ALTER DATABASE [TargetDB] SET MULTI_USER ; /*delete backup file*/ DECLARE @deldate varchar(10)= CONVERT(char, DATEADD(day, +1, GETDATE()), 111); EXECUTE master.dbo.xp_delete_file 0,@path,N'baktmp',@deldate; You ...