Indicate one column as the primary key column : Primary Key « Constraints « PostgreSQL






Indicate one column as the primary key column


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

1.Implicit index is created when creating a table for a primary key
2.Primary keys constrains more than one column
3.PRIMARY KEY will create implicit index
4.Primary key with check option
5.Add PRIMARY KEY in table creation
6.Use sequence value as a primary key