I run into this a lot. What about the file names (physical and logical)? Say, for example you rename a database to indicate an edition or vintage and you plan to reuse the old database name; won't renaming the database leave you with the old mdf/ldf and logical files in place but now being accessed by a "new" (i.e., renamed) database?
Agreed, this example is perhaps a less than ideal way to make editions of databases, say for certified tax rolls for each year. But regardless of whether one plans to use the "old" database name again on the server, one should explicitly keep track of the logical and physical file names.
Thanks for posting the code.