T-SQL 101: 135 What is a Foreign Key Constraint in SQL Server?
Foreign keys are mostly used where you store the primary key of another table, and want to check that it’s valid. This is used to ensure database integrity.
For example, I might have a CustomerID stored in an Orders table, and I want to make sure that the customer already exists. In the example above, I have a Courses table and I want to make sure that the CollegeID that’s stored for each course, actually matches a college that’s already in the Colleges table.
2025-03-26