School DB Lab
Create · Read · Update · Delete

CRUD Lab

The four operations every application performs on every table, walked through on one concrete example: a student record.

وہ چار بنیادی آپریشنز (Create, Read, Update, Delete) جو ہر ایپلیکیشن ڈیٹا بیس ٹیبل پر انجام دیتی ہے، ایک طالب علم کے ریکارڈ کی ٹھوس مثال کے ذریعے مرحلہ وار سمجھائے گئے ہیں۔

1. CREATE

Use the Data Entry Lab to INSERT a new student — that page already covers CREATE in depth.

2. READ

Pick any student below to SELECT and view their full row.

IDNameStatus
20 Hira Basit Active
19 Talha Nadeem Active
18 Amna Riaz Active
17 Yusuf Anwar Active
16 Sana Rafiq Active
15 Bilawal Chaudhry Active
14 Khadija Aslam Active
13 Omar Saeed Active
12 Mariam Yousaf Active
11 Hassan Abbas Active
10 Fatima Noor Active
9 Ahmed Siddiqui Active
8 Mahnoor Iqbal Active
7 Usman Farooq Active
6 Zainab Malik Active
5 Hamza Sheikh Active
4 Ayesha Tariq Active
3 Bilal Raza Active
2 Sara Ahmed Active
1 Ali Khan Active

Viewing: Khadija Aslam (student_id = 14)

SELECT * FROM students WHERE student_id = 14;
student_id14
admission_noADM-2025-014
first_nameKhadija
last_nameAslam
date_of_birth2013-10-05
genderFemale
emailkhadija.aslam14@studentmail.example
phone0300-1110014
statusActive
created_at2026-10-05 14:43:39
updated_at2026-10-05 14:43:39
is_practice_owned0

3. UPDATE

4. DELETE

Before deleting, here's exactly what else in the database points at this student:

TableRows referencing this student
student_enrollments 1 row(s)
attendance 7 row(s)
exam_results 3 row(s)
fee_invoices 2 row(s)
student_parents 1 row(s)
This student has related rows in 5 table(s). Every Foreign Key pointing at students uses ON DELETE RESTRICT, so MySQL will refuse this delete rather than silently destroying academic or financial history. Try it anyway to see the real database error:
Explain this page
Why does DELETE ask so many questions first?
Deleting a student is rarely truly "undo the student existing" — it's usually "this person left the school." Real systems almost always prefer setting status = 'Withdrawn' over a hard DELETE, precisely because a hard delete either destroys history (if cascaded) or gets rejected outright (if restricted, as here).
ڈیلیٹ (DELETE) پہلے اتنے سوال کیوں پوچھتا ہے؟
کسی طالب علم کو ڈیلیٹ کرنا اکثر اوقات "اس طالب علم کا وجود مٹانا" نہیں ہوتا — عام طور پر اس کا مطلب ہوتا ہے "یہ شخص اسکول چھوڑ گیا۔" حقیقی نظاموں میں ہارڈ ڈیلیٹ (Hard DELETE) کی بجائے status = 'Withdrawn' ترجیح دی جاتی ہے، کیونکہ ہارڈ ڈیلیٹ یا تو تاریخی ریکارڈ مٹا دیتا ہے (CASCADE کی صورت میں) یا ڈیٹا بیس اسے مسترد کر دیتا ہے (جیسا کہ یہاں RESTRICT کے ساتھ ہوتا ہے)۔