Alter Table Add Foreign Key Sql Server. Just as you can have a table reference itself in a query JOIN you can have a foreign key that refers back to the same table. Next the ADD FOREIGN KEY clause is followed by the name of the column that will be used as the foreign key.
The table opens in Table Designer. MySQL SQL Server Oracle. A FOREIGN KEY can be defined on a column or multiple columns in the child table while creating a table or later.
The syntax to drop a foreign key in SQL Server Transact-SQL is.
Syntax ALTER TABLE table_name ADD FOREIGN KEY column_name REFERENCE table_nameReferencing column_name in table_name. FOREIGN KEY PresidentID REFERENCES dboPresidents PresidentID cc. Second specify the name of the column its data type and constraint if applicable. Here you will see how to make the student_id attribute foreign key in the exam table which is the primary key in the student table as follows.