Alter Table Add Constraint Foreign Key Sql Server. As shown in the below image. The syntax for creating a foreign key using an ALTER TABLE statement in SQL Server Transact-SQL is.
The easiest way to demonstrate this is with an example. ALTER TABLE child_table ADD CONSTRAINT fk_name FOREIGN KEY child_col1 child_col2. There is an option while adding a Constraint to a table-- Syntax.
Without user defined foreign key name.
Using SQL Server Management Studio To modify a foreign key. Right click on the Keys folder and select New Foreign Key. ALTER TABLE dbostudent add constraint Fk_empid foreign keyemp_id references dboempid. A Foreign Key can accept both null values and duplicate values in SQL Server.