I know syntax for deleting multiple tables is:
DROP TABLE foo, bar, baz;
But in my case 3 tables having foreign keys in between them and with other tables which are not to be deleted.
So how can I drop these 3 tables? They are having data in tables. Will above syntax work ignoring foreign keys? There should not be any data inconsistency in other tables in database.
To drop a foreign key from a table, use the ALTER TABLE clause with the name of the table (in our example, student ) followed by the clause DROP CONSTRAINT with the name of the foreign key constraint.
In SQL Server, you cannot drop a table if it is referenced by a FOREIGN KEY constraint. You have to either drop the child tables before removing the parent table, or remove foreign key constraints.
To drop foreign key (referential) constraints, use the DROP CONSTRAINT clause of the ALTER TABLE statement. When a foreign key constraint is dropped, packages or cached dynamic statements containing the following might be marked as invalid: Statements that insert or update the table containing the foreign key.
How to drop all tables in PostgreSQL? 2 From TablePlus GUI: You can select all the available tables from the right sidebar, right click and choose Delete.. , or press Delete key to drop all. Don't forget to commit changes to the server (Cmd + S) after doing so.
You can tell Postgres to automatically drop all foreign keys referencing those tables by using the cascade
keyword:
DROP TABLE foo, bar, baz CASCADE;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With