What are PRIMARY KEY and FOREIGN KEY constraints?

Beginner

Answer

PRIMARY KEY: Uniquely identifies each record in a table. Cannot be NULL and must be unique.
FOREIGN KEY: Links two tables together, referencing the primary key of another table.

Example:

CREATE TABLE Departments (
    ID INT PRIMARY KEY,
    Name NVARCHAR(50)
);

CREATE TABLE Employees (
    ID INT PRIMARY KEY,
    Name NVARCHAR(50),
    DeptID INT FOREIGN KEY REFERENCES Departments(ID)
);