I have situation where someone mistakenly execute script for creating tables under wrong database.
Let's say we have database DB1
which is some test database, and we have to create other database DB2
. Script for creating tables is intended for DB2
, but someone execute it under DB1.
Now my database DB1
has its own correct tables, and other incorrect tables. I know how to write a select query to view them, and I know that all wrongly created tables were created on a specific date, let's say 2009-12-12
. But the tables are related with foreign keys, and I can't just drop them in the order that they appear, I must first to remove all foreign keys and then drop all of the tables.
Can someone suggest how to do that?
I can do it with cursor, but that is not elegant solution.