I need to build a *.sql script that will remove a database (let's call
it "DB1") and replace it with a brand new empty database (let's call it
"DB2").
Caveat: I don't want to be left with database "DB1" having it's files
confusingly named "DB2.mdf" and "DB2_log.ldf". These two files should
also be renamed to "DB1.mdf" and "DB1_log.ldf" so that outside
customers are not left confused. In addition, I need to be able to
restore the original DB1 if anything goes wrong during, or even after,
the entire process.
Let's assume every customer's *.mdf's and *.ldf's will always reside in
C:\Program Files\Microsoft SQL Server\MSSQL\data folder.
I've researched sp_attach_db, but this looks more appropriate for
moving databases. This isn't what I want to do.
Thank you in advance.