School DB Lab
Break it on purpose, then understand why

Keys & Constraints Lab

Constraints exist to reject bad data. The fastest way to understand one is to trigger it and read MySQL's real error message.

کنسٹرینٹس (Constraints) غلط اور غیر معیاری ڈیٹا کو مسترد کرنے کے لیے لگائے جاتے ہیں۔ انہیں سمجھنے کا سب سے تیز طریقہ یہ ہے کہ جان بوجھ کر غلط ڈیٹا ڈال کر MySQL کے حقیقی ایرر میسج (Error Message) کو پڑھا جائے۔

UNIQUE Constraint Demonstration

Pick a field below and try inserting a value that already exists. Without UNIQUE, two students could accidentally share an admission number; with it, the database itself protects that rule — no application code has to remember to check.

Explain this page
Is a "failed" INSERT here actually a bug?
No — a rejected INSERT on this page is a successful test. The constraint did its job.
What could go wrong without these constraints?
Duplicate admission numbers, enrollments pointing at students that don't exist, blank required fields, and cascading deletes that erase financial history with no way back.
کیا یہاں "ناکام" INSERT دراصل کوئی خرابی ہے؟
نہیں — اس صفحے پر مسترد شدہ INSERT دراصل ایک کامیاب ٹیسٹ ہے۔ کنسٹرینٹ (Constraint) نے اپنا کام درست طریقے سے انجام دیا۔
ان کنسٹرینٹس کے بغیر کیا غلط ہو سکتا ہے؟
ایک جیسے داخلہ نمبر (Admission Numbers)، ایسے داخلوں (Enrollments) کے ریکارڈز جو غیر موجود طلبہ کی طرف اشارہ کریں، ضروری فیلڈز (Fields) خالی چھوڑنا، اور کیسکیڈنگ ڈیلیٹس (Cascading Deletes) جو مالی تاریخ ہمیشہ کے لیے مٹا دیں۔