title: Create copy of database in sql server 2012 express
body: <p>Hello I have database on which user work.
  I want to create copy of this database for testing purpose.</p>
  
  <p>Can anyone tell how can this be done?
  I tried everything from <a href="https://stackoverflow.com/questions/4269450/copy-a-database-within-sql-server-express">copy a database within SQL Server Express?</a></p>
  
  <p>But Copying files and attaching it destroys first database and trying to restore backup into new database throws error that database is not the same.</p>
  
  <p>Can anyone suggest me solution?</p>
  
  <p>as @Nadeem_MK suggested I created backup and now I'm trying to restore with this script:</p>
  
  <pre><code>RESTORE DATABASE [Equipment Test]  -- use your new db name
  FROM  DISK = N'C:\Backup\ExistingDb.bak'  --Path of backup location
  WITH  REPLACE,RECOVERY,  
  MOVE N'Equipment Test' TO N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\ExistingDb.mdf',  --logical name and physical name 
  MOVE N'Equipment Test_log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\ExistingDb.ldf' --logical name and physical name
  </code></pre>
  
  <p>and this throws error:</p>
  
  <pre><code>Msg 1834, Level 16, State 1, Line 1
  The file 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Equipment.mdf' cannot be overwritten.  It is being used by database 'Equipment'.
  Msg 3156, Level 16, State 4, Line 1
  File 'Equipment' cannot be restored to 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Equipment.mdf'. Use WITH MOVE to identify a valid location for the file.
  Msg 1834, Level 16, State 1, Line 1
  
  The file 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Equipment_log.ldf' cannot be overwritten.  It is being used by database 'Equipment'.
  Msg 3156, Level 16, State 4, Line 1
  File 'Equipment_log' cannot be restored to 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Equipment_log.ldf'. Use WITH MOVE to identify a valid location for the file.
  Msg 3119, Level 16, State 1, Line 1
  Problems were identified while planning for the RESTORE statement. Previous messages provide details.
  Msg 3013, Level 16, State 1, Line 1
  RESTORE DATABASE is terminating abnormally.
  </code></pre>
  
  <p>As you can see restores is trying to alter files from backup-ed database instead of new database</p>
  
  <p>@Update: 
  BackUp Script:</p>
  
  <pre><code>--To backup Database (Delete the previous backup first)
  BACKUP DATABASE Equipment --Database Name
  TO DISK = 'C:\Backup\Equipment.bak' WITH INIT --Path of backup location
  </code></pre>
  
  <p>file locations:</p>
  
  <pre><code>C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Equipment.mdf
  C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Equipment_log.ldf
  C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Equipment Test.mdf
  C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Equipment Test_log.mdf
  </code></pre>
  
  <p>Restore function:</p>
  
  <pre><code>RESTORE DATABASE [Equipment Test]  -- use your new db name
  FROM  DISK = N'C:\Backup\Equipment.bak'  --Path of backup location
  WITH  REPLACE,RECOVERY,  
  MOVE N'Equipment Test' TO N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Equipment2.mdf',  --logical name and physical name 
  MOVE N'Equipment Test_log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Equipment_log2.ldf' --logical name and physical name
  </code></pre>