470,580 Members | 2,325 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,580 developers. It's quick & easy.

Need advice for process of swapping DBs

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.

Jul 23 '05 #1
1 906
Simple.. In EM you can right right the database and "All tasks -
Generate SQL Script".. Go through and choose want you want to script
i.e. tables, views, stored procs, constraints, create database etc
etc.. Save the script as a .sql on your computer.. Open the file in a
text editor or SQL QA - modify the create database command and add a
"drop database" command at the top.

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

77 posts views Thread by Charles Law | last post: by
7 posts views Thread by Jack Addington | last post: by
5 posts views Thread by Ekempd | last post: by
22 posts views Thread by Zen | last post: by
7 posts views Thread by John Paul | last post: by
5 posts views Thread by bean330 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.