What is a Primary Key and Foreign Key?

Published July 23, 2025 By Sai Sree Ram Gundepudi

Primary Key

A Primary Key uniquely identifies each record in a table. It cannot be NULL and must be unique.

Example:

CREATE TABLE employees (
  employee_id NUMBER PRIMARY KEY,
  name VARCHAR2(50)
);

Foreign Key

A Foreign Key is a column that creates a relationship between two tables.

CREATE TABLE departments (
  department_id NUMBER PRIMARY KEY,
  name VARCHAR2(50)
);

CREATE TABLE employees (
  employee_id NUMBER PRIMARY KEY,
  name VARCHAR2(50),
  department_id NUMBER REFERENCES departments(department_id)
);

Was this solution helpful?

Your feedback helps improve our technical knowledge repository.

Share this article