nutripolt.blogg.se

Postgres add constraint
Postgres add constraint












PostgreSQL foreign key constraint examples PostgreSQL supports the following actions: Since the primary key is rarely updated, the ON UPDATE action is not often used in practice. The delete and update actions determine the behaviors when the primary key in the parent table is deleted and updated.

  • Finally, specify the delete and update actions in the ON DELETE and ON UPDATE clauses.
  • Third, specify the parent table and parent key columns referenced by the foreign key columns in the REFERENCES clause.
  • Second, specify one or more foreign key columns in parentheses after the FOREIGN KEY keywords.
  • postgres add constraint

    If you omit it, PostgreSQL will assign an auto-generated name. First, specify the name for the foreign key constraint after the CONSTRAINT keyword.REFERENCES parent_table( parent_key_columns) The following illustrates a foreign key constraint syntax: FOREIGN KEY( fk_columns)

    postgres add constraint

    The foreign key constraint helps maintain the referential integrity of data between the child and parent tables.Ī foreign key constraint indicates that values in a column or a group of columns in the child table equal the values in a column or a group of columns of the parent table. In PostgreSQL, you define a foreign key using the foreign key constraint. And the table referenced by the foreign key is called the referenced table or parent table.Ī table can have multiple foreign keys depending on its relationships with other tables. The table that contains the foreign key is called the referencing table or child table.

    postgres add constraint

    Introduction to PostgreSQL Foreign Key ConstraintĪ foreign key is a column or a group of columns in a table that reference the primary key of another table.

    #Postgres add constraint how to#

    Summary: in this tutorial, you will learn about PostgreSQL foreign key and how to add foreign keys to tables using foreign key constraints.












    Postgres add constraint