Foreign Keys Wizard (SQL Server)
Go Up to Microsoft SQL Server Object Wizards
Foreign keys are unique values that refer to specific columns of other tables. Thus, a foreign key links two tables together. The Foreign Key Wizard makes it easy for you to create a relational link between two tables, thereby speeding queries and giving you faster access to data. The column in the initial table, the parent table, is called the primary key. The corresponding column in the (child) table that references the primary key, is the foreign key. Foreign keys can also refer to columns within the same table.
To create a new Foreign Key using a wizard:
- Open a creation wizard for a foreign key. For details, see Opening an Object Wizard.
- Use the following topics as a guide to setting properties and performing tasks as you pass through the wizard panels:
- Properties panel - Foreign Keys (SQL Server) - Properties.
- Column Mapping panel - Foreign Keys (SQL Server) - Column Mapping.
- DDL View panel - for details, see Previewing the DDL Generated to Create the New Object.
- Finally, use the Execute button to create the object.
Foreign Keys (SQL Server) - Properties
When creating or editing a foreign key, this tab/panel lets you work with the following settings:
Setting | Description |
---|---|
Table Owner and Table Name |
Select the owner and name of the table for which the foreign key is being created. |
Name |
Provide a name for the foreign key. |
Enabled |
Enables or disables the foreign key. |
With NOCHECK |
Specifies whether the data in the table is validated against a newly added or re-enabled foreign key. |
Not For Replication |
Replication copies and distributes data and database objects from one database to another and then synchronizes information between databases for consistency. |
Delete Rule |
If you choose the CASCADE option, all rows containing data involved with the foreign key will be deleted after a delete operation. |
Update Rule |
If you choose the CASCADE option, all rows containing data involved with the foreign key will be deleted after an update operation. |
Foreign Keys (SQL Server) - Column Mapping
Under Referenced Table, choose the Owner and then the Name of the referenced, or parent, table.
Under the Main Table, select check boxes corresponding to the columns that are to reference columns in the referenced table. Then, under Referenced Table, select the corresponding column check boxes.