🔑 Difference Between Primary Key and Unique Key in SQL
📘 Definition
In SQL, both Primary Key and Unique Key are used to enforce uniqueness of records in a table — but they serve slightly different purposes and have different rules.
🔍 1. Primary Key
✅ Example:
CREATE TABLE Students (
student_id INT PRIMARY KEY,
name VARCHAR(50)
);
🧩 2. Unique Key
✅ Example:
CREATE TABLE Students (
student_id INT PRIMARY KEY,
email VARCHAR(100) UNIQUE
);
📊 Comparison Table
🧠 Real-World Analogy