![]() 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.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) 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. ![]() 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. Summary: in this tutorial, you will learn about PostgreSQL foreign key and how to add foreign keys to tables using foreign key constraints. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |