Click here to Skip to main content
15,790,795 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hey, I'm trying to the tables that my application is creating, and of course there are foreign key relations between tables. There are of course some limitations... Tables that have foreign key must be created after the foreign key column exists in its original table, and of course... you can't delete a table whose column is a foreign key somewhere else. So the creating and dropping problem. It seems like a classic case to implement a topological sort on the table structure (of course, assuming that there are no circular dependencies in the design...). Is there a way to create or drop all tables without the sort, except for of course actually implementing the topological sort manually, and choosing a valid creation sequence?

You can disable the constraint check and do what ever you want.

See :[^]
Share this answer
ShacharK 20-Oct-11 4:50am    
According to what you're saying, there shouldn't be any problem with the DROP, but what about the creation? Can I create "randomly" my tables, with my foreign key constraints turned off, and only eventually, after the whole database is built, to actually turn them on (without the SQL telling me that it couldn't find the column that I was referring to)
Mehdi Gholam 20-Oct-11 4:56am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900