School DB Lab
Trust, but verify

Data Integrity Checker

Because every Foreign Key and UNIQUE constraint in this schema is enforced, every check below should show PASS on a healthy database seeded through seed.sql. Deliberately-broken data would show up here immediately.

چونکہ اس اسکیما (Schema) میں تمام فارن کیز (Foreign Keys) اور یونیک کنسٹرینٹس (UNIQUE Constraints) سختی سے نافذ ہیں، اس لیے seed.sql سے تیار کردہ صحت مند ڈیٹا بیس پر نیچے دیا گیا ہر ٹیسٹ PASS ہونا چاہیے۔ اگر ڈیٹا میں جان بوجھ کر خرابی کی گئی ہو تو وہ یہاں فوری طور پر سامنے آ جائے گی۔

Overall: ALL CHECKS PASS

Enrollments with missing students

PASS
SELECT e.enrollment_id, e.student_id FROM student_enrollments e LEFT JOIN students s ON s.student_id = e.student_id WHERE s.student_id IS NULL;

Enrollments with missing classes

PASS
SELECT e.enrollment_id, e.class_id FROM student_enrollments e LEFT JOIN classes c ON c.class_id = e.class_id WHERE c.class_id IS NULL;

Results with missing exams

PASS
SELECT r.result_id, r.exam_id FROM exam_results r LEFT JOIN exams e ON e.exam_id = r.exam_id WHERE e.exam_id IS NULL;

Results with missing students

PASS
SELECT r.result_id, r.student_id FROM exam_results r LEFT JOIN students s ON s.student_id = r.student_id WHERE s.student_id IS NULL;

Invoices with missing students

PASS
SELECT i.invoice_id, i.student_id FROM fee_invoices i LEFT JOIN students s ON s.student_id = i.student_id WHERE s.student_id IS NULL;

Payments with missing invoices

PASS
SELECT p.payment_id, p.invoice_id FROM fee_payments p LEFT JOIN fee_invoices i ON i.invoice_id = p.invoice_id WHERE i.invoice_id IS NULL;

Parent links with missing students

PASS
SELECT sp.student_parent_id, sp.student_id FROM student_parents sp LEFT JOIN students s ON s.student_id = sp.student_id WHERE s.student_id IS NULL;

Teacher assignments with missing entities

PASS
SELECT cst.assignment_id FROM class_subject_teachers cst LEFT JOIN classes c ON c.class_id=cst.class_id LEFT JOIN subjects sub ON sub.subject_id=cst.subject_id LEFT JOIN teachers t ON t.teacher_id=cst.teacher_id WHERE c.class_id IS NULL OR sub.subject_id IS NULL OR t.teacher_id IS NULL;
Explain this page
What is an orphan record?
A row whose Foreign Key value points at a parent row that no longer exists — for example, an enrollment referencing a student_id that was deleted. This schema's Foreign Keys make orphans structurally impossible through the application; this page is what you'd run to check a database that was loaded some other way (e.g. a raw data import).
How do we detect duplicates?
GROUP BY collapses rows that share the same value(s) into one group; HAVING COUNT(*) > 1 then keeps only the groups with more than one row — i.e. the duplicates. HAVING filters groups, the way WHERE filters individual rows.
یتیم ریکارڈ (Orphan Record) کیا ہے؟
وہ قطار جس کی فارن کی (Foreign Key) ویلیو کسی ایسے پیرنٹ ریکارڈ کی طرف اشارہ کر رہی ہو جو اب موجود نہ ہو — مثلاً، ایک داخلہ (Enrollment) جو کسی حذف شدہ طالب علم کی student_id سے منسلک ہو۔ اس اسکیما کی فارن کیز ایپلیکیشن کے ذریعے یتیم ریکارڈز کو ساختی طور پر ناممکن بنا دیتی ہیں؛ یہ صفحہ اس صورت میں مفید ہے جب ڈیٹا بیس کوئی دوسرے طریقے سے لوڈ ہوا ہو (مثلاً خام ڈیٹا درآمد)۔
ڈپلیکیٹس (Duplicates) کو کیسے پہچانیں؟
GROUP BY ایک جیسی ویلیوز والی قطاروں کو ایک گروپ میں جمع کرتا ہے؛ پھر HAVING COUNT(*) > 1 صرف وہ گروپ رکھتا ہے جن میں ایک سے زیادہ قطاریں ہوں — یعنی ڈپلیکیٹس۔ HAVING گروپوں کو فلٹر کرتا ہے، جیسے WHERE انفرادی قطاروں کو فلٹر کرتا ہے۔