One table inherits another table : INHERITS « Inheritance « PostgreSQL






One table inherits another table


postgres=#
postgres=# CREATE TABLE "authors" (
postgres(#      "id" integer NOT NULL,
postgres(#      "last_name" text,
postgres(#      "first_name" text,
postgres(#      Constraint "authors_pkey" Primary Key ("id")
postgres(# );
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "authors_pkey" for table "authors"
CREATE TABLE
postgres=#
postgres=#
postgres=# CREATE TABLE distinguished_authors (award text)
postgres-#               INHERITS (authors);
CREATE TABLE
postgres=#
postgres=# \d distinguished_authors
Table "public.distinguished_authors"
   Column   |  Type   | Modifiers
------------+---------+-----------
 id         | integer | not null
 last_name  | text    |
 first_name | text    |
 award      | text    |
Inherits: authors

postgres=#
postgres=# drop table distinguished_authors;
DROP TABLE
postgres=# drop table authors;
DROP TABLE
postgres=#
           
       








Related examples in the same category