I have a ELMAH database that I want to script the restore of using the following:

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


Even though I am not including WITH REPLACE each time I execute this statement it restores over the existing database.

I will always drop all databases before this operation and I never want this code to accidentally restore a database over one in production.

How do I change this code so that it will never overwrite an existing database?

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.


Question: No value for $TERM and no -T specified
Answer: Try opening terminal (doesn't matter which, even tty1 will do) and run this line

sudo update-alternatives --config x-terminal-emulator

You will be presented with choice of the default terminal emulator for x window. Choose one by selecting number, and reboot after you're done.

$ sudo update-alternatives --config x-terminal-emulator
There are 6 choices for the alternative x-terminal-emulator (providing /usr/bin/x-terminal-emulator).

  Selection    Path                             Priority   Status
------------------------------------------------------------
  0            /usr/bin/gnome-terminal.wrapper   40        auto mode
  1            /usr/bin/gnome-terminal.wrapper   40        manual mode
  2            /usr/bin/koi8rxterm               20        manual mode
* 3            /usr/bin/lxterm                   30        manual mode
  4            /usr/bin/sakura                   40        manual mode
  5            /usr/bin/uxterm                   20        manual mode
  6            /usr/bin/xterm                    20        manual mode

Press enter to keep the current choice[*], or type selection number: