Sample Header Ad - 728x90

DROP TABLE ... CASCADE does not drop any dependent table

11 votes
2 answers
44083 views
I am still relatively new to postgres and I was just finishing an assignment when I decided to try something which was to drop a table which other tables depend on due to a foreign key relationship. My expectation was that any table that had a foreign key reference to the table I am dropping will have (at least) all their rows deleted and the table dropped as well. This was not the case. The tables are still there and even though I specified CASCADE, nothing happened to the rows of those tables. However using TRUNCATE ... CASCADE on the referenced table does in fact remove the rows in the other tables ***EDIT:*** Ok, I understand it does this because this is the way it has been specified by the documentation, but my question now is, when is this ever expected behaviour? - DROPing a domian with CASCADE removes every column in any table that uses that domain. - DROPing a table with a view attached to it will delete the view. **Why does it make sense that dropping a table which is referenced by other tables does not delete the tables that reference this one as well? Convienience?**
Asked by smac89 (215 rep)
Oct 7, 2015, 07:44 AM
Last activity: Oct 5, 2022, 06:26 AM