Unique Email Among Active Users
Medium
Integrity & Constraints
Users are soft deleted (deleted_at IS NOT NULL). Create a constraint so that no two active users share an email, while deleted users may keep duplicate emails.
Table schema
Users(id INT PRIMARY KEY, email VARCHAR(100), deleted_at TIMESTAMP NULL)Sample data
Rows: (1, a@x.com, NULL), (2, a@x.com, 2026-01-01). Inserting another active a@x.com must fail.
Discussion
No discussions yet.
Shalyam Support
Hi! Ask us anything — we'll reply on WhatsApp or Telegram within 24 hours.