Search code examples
sqlpostgresqlsingle-table-inheritance

What is the steps for splitting childs table in postgresql?


I have a Postgresql database, where many tables inherit from a common root table.

What are the SQL commands to use for removing the root table, but keeping data and final schema for each table?

Thanks.


Solution

  • A parent table cannot be dropped while any of its children remain. Neither can columns or check constraints of child tables be dropped or altered if they are inherited from any parent tables. If you wish to remove a table and all of its descendants, one easy way is to drop the parent table with the CASCADE option.

    Source