Add PRIMARY KEY in table creation : Primary Key « Constraints « PostgreSQL






Add PRIMARY KEY in table creation


postgres=#
postgres=# CREATE TABLE new_books
postgres-#               (id integer CONSTRAINT books_id_pkey PRIMARY KEY,
postgres(#               title text NOT NULL,
postgres(#               author_id integer,
postgres(#               subject_id integer);
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "books_id_pkey" for table "new_books"
CREATE TABLE
postgres=#
postgres=# drop table new_books;
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.Indicate one column as the primary key column
4.PRIMARY KEY will create implicit index
5.Primary key with check option
6.Use sequence value as a primary key