What is foreign key SQL SERVER constraint?
How to set Foreign key in SQL SERVER For Existing Table Made Simple.
For More Sql Server Constraints
->A Foreign key is used to link two tables.
->Foreign key is a one table point to another table.
->Foreign key can accept multiple NULL values.
->We can have more than one Foreign key in a table.
How to create Foreign Key in SQL SERVER by Query?
CREATE TABLE Employee(
EmpId int NOT NULL PRIMARY KEY identity(1,1),
EmpName Varchar(200),
Department varchar(200),
CompanyId int FOREIGN KEY REFERENCES Company (CId)
);
where:-
Employee - Table name 2
Company - Table Name 1
CId - Table 1 Column name(Primary key)
CompanyId - table 2 Column name(Foreign Key)
Foreign Key |