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) کو پڑھا جائے۔
NOT NULL Demonstration
Try inserting a student with no admission_no. This column is declared
NOT NULL because an admission number is how the whole school identifies the
student — a student with no admission number could never be found or booked correctly again.
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) جو مالی تاریخ ہمیشہ کے لیے مٹا دیں۔