SQL Server Add Foreign Key Constraints

DBHawk includes an Add Foreign Key Constraints feature.

After creating SQL Server Table, you may want to add Primary and Foreign Key constraints.

The add column part in the wizard let me add the default constraints, but I want a foreign key from ManagerID to EmployeeID.   Checked the ‘Options’ drop down and found what I needed.

First, add new Primary Key Constraint.

SQL Server Add Constraints

SQL Server Add Constraints

Clicked on the ‘Constraints’ menu and up popped the ‘New Constraint’ wizard.  Created a primary key on EmployeeID and then created a foreign key from ManagerID to EmployeeID.  The tool went ahead and created a unique clustered index on the primary key.

SQL Server Add Foreign Key

SQL Server Add Foreign Key

For more details about how to create foreign key  relationships visit MS SQL Document

top