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) کو پڑھا جائے۔

Foreign Key Demonstration

Try enrolling a student id that does not exist. student_enrollments.student_id has a Foreign Key that requires a matching students.student_id — MySQL checks this on every INSERT, before the row is ever written.

Expect this to fail. That's the point — Foreign Keys exist precisely to stop orphan records like this from ever being created.

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) جو مالی تاریخ ہمیشہ کے لیے مٹا دیں۔