title: How to stop SQL server restore from overwriting database?
body: <p>I have a ELMAH database that I want to script the restore of using the following:</p>
  
  <pre><code>RESTORE DATABASE [Elmah] 
  FROM DISK = N'E:\Elmah_backup_2012_11_02_030003_1700702.bak' 
  WITH FILE = 1,  
  MOVE N'Elmah' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Elmah.mdf',  
  MOVE N'Elmah_log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Elmah.ldf',  
  NOUNLOAD, STATS = 10
  GO
  </code></pre>
  
  <p>Even though I am not including <code>WITH REPLACE</code> each time I execute this statement it restores over the existing database.</p>
  
  <p>I will always drop all databases before this operation and I never want this code to accidentally restore a database over one in production.</p>
  
  <p>How do I change this code so that it will never overwrite an existing database?</p>
  
  <p>I am actually doing this through SMO objects but the principle and results are the same so I am hoping to keep this simplified to just the TSQL necessary in the hopes that I can generalize that information to what needs to be set on the appropriate SMO.Restore object.</p>