When a value other than NULL is entered into the column of a FOREIGN KEY constraint, the value must exist in the referenced column. Foreign keys can also be defined to reference the columns of a UNIQUE constraint in another table.
Limits and restrictionsĪ foreign key constraint doesn't have to be linked only to a primary key constraint in another table.
PermissionsĬreating a new table with a foreign key requires CREATE TABLE permission in the database, and ALTER permission on the schema in which the table is being created.Ĭreating a foreign key in an existing table requires ALTER permission on the table. You create a relationship between two tables when you want to associate rows of one table with rows of another.
This article describes how to create foreign key relationships in SQL Server by using SQL Server Management Studio or Transact-SQL. Applies to: SQL Server 2016 (13.x) and later Azure SQL Database Azure SQL Managed Instance