copy a database within SQL Server Express?

Sql ServerSql Server-Express

Sql Server Problem Overview


I would like to make a copy of a database I have but keep it on the same server as a test database. However, everything I have found is to use the copy database wizard (I am using MS SQL Server Express).

The instructions always say: In SQL Server Management Studio, in Object Explorer, expand Databases, right-click a database, point to Tasks, and then click Copy Database.

I don't have the Copy Database option. I am running as an admin, so no clue why it is missing for me - is it something I have to install separately? I can't do the Detach/Attach since it is copying to the same server. I tried detaching, copying the MDF/LDF, renaming, attaching but as you can imagine that messed a ton up :) I am not great with SQL to do it all programatically. Is there a tool out there I could use?

Sql Server Solutions


Solution 1 - Sql Server

In SSMS 2008 you can do this:

  1. Create a backup of the database you want to copy

  2. In SSMS, right-click 'Databases' and select 'Restore Database'

  3. Select the database you wish to copy from the 'From database' drop-down list in the 'Source for restore' section

  4. Enter the name of the new database in the 'To database' field in the 'Destination for Restore' section - this cannot be the name of an existing database.

  5. Click OK

You're done! :)

Solution 2 - Sql Server

In SQL Server Express 2012 you can do following steps:

  1. Create a backup of the database you want to copy
  2. right-click "Databases" and select "Restore Files and Filegroups"
  3. Enter the name of the new database in the "To database" field.
  4. Select "From device" and then select the file that you backuped in the first step
  5. click "OK"

this will "clone" the Database with the correct table settings such as the "default value" and "auto increase" etc.

Solution 3 - Sql Server

SQL Express database has an export button, I just exported the database to a new database on the same server, it is copying the database. Just right-click on the database name.

Solution 4 - Sql Server

Take these steps to make a copy of the database in SQL Express

  1. Stop SQL
  2. Copy the mdf, ldf and any other file for the db to a NEW location (make sure you get the log file)
  3. Change the name of each copied file
  4. Start SQL
  5. Right-click Database in SSMQ and select attach
  6. Make sure you change the name in the column "Attach As"
  7. Update the file location in the lower pane of "Database Details" to the location of your copied files (especially that log file)

I was able to copy a database on my SQL Express system with this method

alt text

Solution 5 - Sql Server

I had a problem creating a copy of my database as well using SQL Express 2012. I have solved it by the backup and restore method. After making the backup I used: restore -> files and file groups choosing restore option

Next step was to write a new name for the new database and set the source:

set source and named new database

Pointing the source file

choosing backup file

and finally, a overwrite the existing database with replace must be selected and set names for new files with extension mdf and ldf that are different from the existing where is: Restore as

set new names for mdf and ldf files

This method worked for me

Solution 6 - Sql Server

Just be aware if you are using SQL Server Express 2012 of going to the option Files and make sure that the destination files (Restore As column) are different from the original files *.mdf and *.log

( I tried to put an image but need 10 reputation :p)

Solution 7 - Sql Server

I do not believe the Express version of the manager will have the copy database feature. Have you considered copying via the backup and restore method?

http://msdn.microsoft.com/en-us/library/ms190436.aspx

Solution 8 - Sql Server

The solution is definitely to create a backup and restore it, but ensure that you're restored copy is pointing to different .mdf and .ldf files.

Here's how to check that using SSMS 2014 and a SQL Server 12 installation: assuming you're creating and restoring backups on your local disk.

  • Create a backup of your existing database
  • Right click the database, and choose "back up..." under "tasks."
  • (If you leave the location as the default, you don't have to hunt for the back up in the next step when you restore.)
  • Restore your backup to a NEW database:
  • Right click on databases, choose "restore database"
  • Select "device"
  • Click the ellipsis button ("...") to open the "Selct Backup devices" dialog.
  • Choose "File" as the backup media type and click the "add" button
  • Select the backup you just made, click ok (twice)
  • Now, back in the "restore database" dialog, type a new name for your destination database
  • Click "files" under "select a page" and make sure that "restore as" is pointing to .mdf and .ldf file names that do not already exist
  • Click ok!

Solution 9 - Sql Server

I found the problem! Click on Databases, restore, then do the following: After choosing from where to restore, and writing destination db name, go to files [annotation 1 on picture] and change the very right column files names to different than original [annotation 2 on picture] then it works :)

> SEE THE PICTURE HERE <

Solution 10 - Sql Server

I just thought of a really nifty way to get around this :) So I thought I should post my idea. Note that this is 'untested' but I think it will work.

  1. Do a "Back Up..." database (theoretically this is on your production server, but it doesn't have to be)
  2. Copy the backup file (from your prod server) onto your development machine
  3. Assuming you're using SSMS Developer Edition on your development machine, you can then do a "Restore" onto your development machine, then do a "Copy Database" afterwards also on your development machine (to create a new copy of the DB)
  4. Now do a "Back Up..." on the new DB you just created, copy the backup file (to your production server) and do a "Restore" on the sql server express server :)

Hope this helps out a few people :)

Cheers,

Jeff

Solution 11 - Sql Server

I think you could try import data to a new database.

  1. Create an empty database in your local sql server
  2. Right click on the new database -> tasks -> import data
  3. In the SQL Server Import and Export Wizard, select product env's servername as data source. And select your new database as the destination data.

Solution 12 - Sql Server

As for the first part of your question (why do you not see this Copy Database Wizard option under Tasks for your dbs), the answer is indeed in the fact that you are running SQL Server Express. SQL Server Express doesn't support the SQL Server Agent feature, which this Copy DB feature relies upon, so the Copy DB feature is not shown (but many online resources fail to make that observation).

Fortunately, most everyone else has addressed the second part of your question (how to achieve the task otherwise), and nearly all point out using the existing backup and restore options (which DO exist in Express), or the export/import (which also exists in Express, I can confirm).

Solution 13 - Sql Server

Try making a backup of your database, and restoring it into a brand new database.

  • Create new DB.
  • Make a full backup of your original.
  • Right click on your new DB, hit restore.
  • Navigate to your .BAK, and ensure the .mdf and .ldf match the new.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJennView Question on Stackoverflow
Solution 1 - Sql ServerSteve WilkesView Answer on Stackoverflow
Solution 2 - Sql ServerrekinyzView Answer on Stackoverflow
Solution 3 - Sql ServerDmitriySidyakinView Answer on Stackoverflow
Solution 4 - Sql ServerRC_ClelandView Answer on Stackoverflow
Solution 5 - Sql ServerKiril DobrevView Answer on Stackoverflow
Solution 6 - Sql ServervaldessirView Answer on Stackoverflow
Solution 7 - Sql ServerjohnnyView Answer on Stackoverflow
Solution 8 - Sql ServerRoseView Answer on Stackoverflow
Solution 9 - Sql ServerDiSaSteRView Answer on Stackoverflow
Solution 10 - Sql ServerJeff MorettiView Answer on Stackoverflow
Solution 11 - Sql ServermaoyangView Answer on Stackoverflow
Solution 12 - Sql Servercharlie arehartView Answer on Stackoverflow
Solution 13 - Sql Serverp.campbellView Answer on Stackoverflow