Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9171549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:10:41+00:00 2026-06-17T16:10:41+00:00

I want to copy a database A into database B (same SQL Server) entirely

  • 0

I want to copy a database A into database B (same SQL Server) entirely – what would be the easiest SQL or utility command to do that? (database B should be 100% erased before the copy)

Note that it can be non-SQL thing, but in any case I need to run it as one-click. So some utility that does that is also acceptable as far as I can run copying with one click or from command line.

SQL Server 2008R2 or 2012.

Best, Askar

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:10:41+00:00Added an answer on June 17, 2026 at 4:10 pm

    I made a soultion based on David’s thoughts. It looks like this (Prod – source DB, Demo – destination copy)

     DECLARE @backup varchar(300) = 'e:\Prod.bak'; 
     DECLARE @logic_db_file varchar(300) = 'koe'; 
     DECLARE @logic_log_file varchar(300) = 'koe_log'; 
     DECLARE @out_db_file varchar(300) = 'c:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Demo.mdf'; 
     DECLARE @out_log_file varchar(300) = 'c:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Demo_log.ldf'; 
    
     PRINT N'Backing up Production database.'
     BACKUP DATABASE Prod
        TO DISK = @backup WITH FORMAT;
    
    
     PRINT N'Restoring FILELISTONLY, see log file for data.'
     -- Restore the files to Demo
     RESTORE FILELISTONLY
        FROM DISK = @backup
    
     PRINT N'Getting exclusive access to Demo'  
     Alter database  Demo set single_user with rollback immediate
     drop database Demo
    
    
    
     PRINT N'Restoring backup to Test database'
     RESTORE DATABASE Demo
      FROM DISK = @backup
      WITH REPLACE,
      MOVE @logic_db_file TO @out_db_file, 
      MOVE @logic_log_file TO @out_log_file
     GO
    
      -- if you want you can do some SQL fixes to newly made DB
    
      PRINT N'Changing normal users to demo users, if account type is OK'
    
      USE Demo; 
      UPDATE USER_ACCOUNTS SET ACCOUNT_TYPE=3 WHERE (STATUS=1) AND (ACCOUNT_TYPE=1);  
      GO    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database schema in SQL 2005 that I want to copy to
I have a SQL Server database where I want to copy parts of the
I have a SQL Server 2000 database with 7 tables. I want to copy
So I want to copy just the data from a Prod database (SQL 2005)
I have 2 SQL Server atabases A and B and want to copy a
I want to be able to copy a database into a byte array and
I use SQL Server 2008. I have a database (Database1) that has one table
I am importing an Excel sheet into a SQL Server database. I am able
I have 2 tables on 2 database on the same server . I want
I want copy lib dependencies in maven into lib directory when install project. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.