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.
| ID | Name | Status |
|---|---|---|
| 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: Fatima Noor (student_id = 10)
SELECT * FROM students WHERE student_id = 10;
| student_id | 10 |
|---|---|
| admission_no | ADM-2025-010 |
| first_name | Fatima |
| last_name | Noor |
| date_of_birth | 2014-08-16 |
| gender | Female |
| fatima.noor10@studentmail.example | |
| phone | 0300-1110010 |
| status | Active |
| created_at | 2026-10-05 14:43:39 |
| updated_at | 2026-10-05 14:43:39 |
| is_practice_owned | 0 |
3. UPDATE
4. DELETE
Before deleting, here's exactly what else in the database points at this student:
| Table | Rows referencing this student |
|---|---|
| student_enrollments | 1 row(s) |
| attendance | 0 rows |
| exam_results | 0 rows |
| fee_invoices | 2 row(s) |
| student_parents | 2 row(s) |
This student has related rows in 3 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 کے ساتھ ہوتا ہے)۔