Tutorial by Examples

Foreign keys enables you to define relationship between two tables. One (parent) table need to have primary key that uniquely identifies rows in the table. Other (child) table can have value of the primary key from the parent in one of the columns. FOREIGN KEY REFERENCES constraint ensures that valu...
Let's assume that we have one row in Company table with companyId 1. We can insert row in employee table that has companyId 1: insert into Employee values (17, 'John', 1) However, we cannot insert employee that has non-existing CompanyId: insert into Employee values (17, 'John', 111111) Msg ...
FOREIGN KEY constraint can be added on existing tables that are still not in relationship. Imagine that we have Company and Employee tables where Employee table CompanyId column but don't have foreign key relationship. ALTER TABLE statement enables you to add foreign key constraint on an existing c...
FOREIGN KEY columns with constraint can be added on existing tables that are still not in relationship. Imagine that we have Company and Employee tables where Employee table don't have CompanyId column. ALTER TABLE statement enables you to add new column with foreign key constraint that references ...
sys.foreignkeys system view returns information about all foreign key relationships in database: select name, OBJECT_NAME(referenced_object_id) as [parent table], OBJECT_NAME(parent_object_id) as [child table], delete_referential_action_desc, update_referential_action_desc from sys.foreign...

Page 1 of 1