# Databases : PostgreSQL : Advanced : Inheritance ``` CREATE TABLE bar ( ...column definitions... ) INHERITS ( foo ); Querying foo will also return rows from bar (without bar's extra columns) unless: SELECT ... FROM ONLY foo ; # also works with UPDATE, DELETE WARNING: Although inheritance is frequently useful, it has not been integrated with unique constraints or foreign keys, which limits its usefulness. You can select the c.tableoid column to see which table each row comes from. Join with pg_class to see the actual table names: SELECT p.relname, c.name, c.elevation FROM cities c, pg_class p WHERE c.elevation > 500 AND c.tableoid = p.oid; (can do same using "regclass" alias type) SELECT c.tableoid::regclass, c.name, c.elevation FROM cities c WHERE c.elevation > 500; Can inherit from multiple parents, but that's weird and complicated. Can add or remove parents with ALTER TABLE. Use the LIKE clause in CREATE TABLE to creates a new table with the same columns as the source table. If there are any CHECK constraints defined on the source table, the INCLUDING CONSTRAINTS option to LIKE should be specified. Commands that do database maintenance and tuning (e.g., REINDEX, VACUUM) typically only work on individual, physical tables and do not support recursing over inheritance hierarchies. A serious limitation of the inheritance feature is that indexes (including unique constraints) and foreign key constraints only apply to single tables, not to their inheritance children. ```