SQL Fundamentals · Course lab · about 150 minutes · 6 tasks · marked out of 100, pass at 60
The academy database, built and queried
The situation
A training academy keeps students, courses and enrolments in three spreadsheets that disagree with each other. You will design the three tables properly, load them with realistic rows, and answer the questions the office actually asks — including the one every SQL interview asks and the deletion you must never run without looking first.
What you'll be able to show
- Design tables with keys that refer to each other, before writing any SQL
- Filter, sort, group and join with confidence
- Say a query in plain words before writing it
- Handle a deletion the professional way: look, prefer an update, delete only when told
What you need
- DB Browser for SQLite (free), or MySQL if you already have it
- A .sql file you keep — it is day one of your portfolio
Tasks
-
1Design on paperWrite the three tables — students (id, name, city, phone, admission_date), courses (id, title, fee), enrollments (id, student_id, course_id, fee_paid, enrolled_on) — and mark which column in enrollments refers to which table. Write one sentence on why enrolments are not a column in students.A correct result: Three table definitions with the two foreign keys marked, and the sentence.
-
2Create and loadCREATE the three tables with primary keys. INSERT at least 15 students across four cities, 4 courses, and 20 enrolments — including two students with no enrolment and one student enrolled in two courses.A correct result: SELECT COUNT(*) gives 15, 4 and 20; the three special cases exist by name.
-
3Filter and sortWrite and run: students from one city; enrolments where fee_paid is below 30,000, lowest first; the five most recent admissions. Say each aloud in plain words before writing it.A correct result: Three queries with their results pasted.
-
4GroupTotal fee collected per course title; number of students per city; cities with at least three students (HAVING).A correct result: Three grouped results; the HAVING one drops at least one city.
-
5Join — including the interview questionEvery student name with every course title they are enrolled in; total fees per course title; and the names of students with NO enrolment at all (a LEFT JOIN with a NULL test).A correct result: Three joined results; the third lists exactly your two unenrolled students.
-
6The deletion, done properlyStudent id 8 has left. Write, in order: the SELECT you run first to see everything you would touch (their row and their enrolments); the UPDATE that marks them inactive instead (add a status column); and the DELETE you would run only if told the record must go, with the expected row count for each.A correct result: Three statements in the professional order, each with its expected row count, the DELETE not executed.
What to hand in
The .sql file with every CREATE, INSERT and query, and a results document with each query's output pasted under it.
How it is marked
| Criterion | Points |
|---|---|
| Design has correct keys and the reasoning sentence | 15 |
| Tables created and loaded with the three special cases | 15 |
| Filter, sort and group queries are correct | 25 |
| Joins are correct, including the unenrolled-students query | 25 |
| Deletion handled in the professional order with counts | 20 |
| Total · pass at 60 | 100 |
صورتحال
ایک training academy students، courses اور enrolments کو تین spreadsheets میں رکھتی ہے جو ایک دوسرے سے میل نہیں کھاتیں۔ آپ تینوں tables ٹھیک سے design کریں گے، انہیں حقیقت پسندانہ قطاروں سے بھریں گے، اور وہ سوال حل کریں گے جو دفتر واقعی پوچھتا ہے — بشمول وہ جو ہر SQL interview میں پوچھا جاتا ہے اور وہ deletion جو آپ کو پہلے دیکھے بغیر کبھی نہیں چلانی۔
آپ کیا دکھا سکیں گے
- کوئی SQL لکھنے سے پہلے ایسی tables design کرنا جن کی keys ایک دوسرے کی طرف اشارہ کریں
- اعتماد سے filter، sort، group اور join کرنا
- query لکھنے سے پہلے اسے سادہ الفاظ میں کہنا
- deletion کو پیشہ ورانہ طریقے سے سنبھالنا: دیکھیں، update کو ترجیح دیں، delete صرف کہنے پر
آپ کو کیا چاہیے
- DB Browser for SQLite (مفت)، یا MySQL اگر آپ کے پاس پہلے سے ہے
- ایک .sql file جو آپ رکھیں گے — یہ آپ کے portfolio کا پہلا دن ہے
کام
-
1کاغذ پر designتینوں tables لکھیں — students (id، name، city، phone، admission_date)، courses (id، title، fee)، enrollments (id، student_id، course_id، fee_paid، enrolled_on) — اور نشان لگائیں کہ enrollments کا کون سا column کس table کی طرف اشارہ کرتا ہے۔ ایک جملہ لکھیں کہ enrolments students میں ایک column کیوں نہیں ہیں۔درست نتیجہ: تین tables کی تعریفیں دو foreign keys کے نشان کے ساتھ، اور جملہ۔
-
2بنائیں اور بھریںprimary keys کے ساتھ تینوں tables CREATE کریں۔ چار شہروں میں کم از کم 15 students، 4 courses، اور 20 enrolments INSERT کریں — بشمول دو students جن کا کوئی enrolment نہیں اور ایک student جو دو courses میں enrolled ہے۔درست نتیجہ: SELECT COUNT(*) سے 15، 4 اور 20 آئے؛ تینوں خاص cases نام سے موجود ہوں۔
-
3filter اور sortلکھیں اور چلائیں: ایک شہر کے students؛ وہ enrolments جہاں fee_paid 30,000 سے کم ہو، سب سے کم پہلے؛ پانچ سب سے حالیہ داخلے۔ ہر ایک لکھنے سے پہلے سادہ الفاظ میں بلند آواز میں کہیں۔درست نتیجہ: تین queries اپنے نتائج paste کیے ہوئے۔
-
4groupہر course title کی کل وصول فیس؛ ہر شہر کے students کی تعداد؛ وہ شہر جہاں کم از کم تین students ہیں (HAVING)۔درست نتیجہ: تین grouped نتائج؛ HAVING والا کم از کم ایک شہر خارج کرے۔
-
5join — interview کے سوال سمیتہر student کا نام اس کے ہر enrolled course کے title کے ساتھ؛ ہر course title کی کل فیس؛ اور ان students کے نام جن کا کوئی enrolment نہیں (NULL test کے ساتھ LEFT JOIN)۔درست نتیجہ: تین joined نتائج؛ تیسرا بالکل آپ کے دو unenrolled students دکھائے۔
-
6deletion، ٹھیک طریقے سےstudent id 8 چلا گیا ہے۔ ترتیب سے لکھیں: وہ SELECT جو آپ پہلے چلاتے ہیں تاکہ ہر وہ چیز دیکھیں جسے آپ چھوئیں گے (اس کی قطار اور اس کے enrolments)؛ وہ UPDATE جو اس کے بجائے انہیں inactive نشان زد کرے (ایک status column شامل کریں)؛ اور وہ DELETE جو آپ صرف تب چلائیں گے جب کہا جائے کہ record جانا چاہیے، ہر ایک کے متوقع row count کے ساتھ۔درست نتیجہ: پیشہ ورانہ ترتیب میں تین statements، ہر ایک کے متوقع row count کے ساتھ، DELETE چلایا نہیں گیا۔
کیا جمع کروانا ہے
ہر CREATE، INSERT اور query کے ساتھ .sql file، اور ایک نتائج کا document جس میں ہر query کا output اس کے نیچے paste ہو۔
نمبر کیسے ملیں گے
| معیار | نمبر |
|---|---|
| design میں درست keys اور وجہ کا جملہ ہے | 15 |
| tables بنیں اور تینوں خاص cases کے ساتھ بھریں | 15 |
| filter، sort اور group کی queries درست ہیں | 25 |
| joins درست ہیں، unenrolled students والی query سمیت | 25 |
| deletion پیشہ ورانہ ترتیب اور counts کے ساتھ سنبھالی گئی | 20 |
| کل · پاس 60 | 100 |
Hand in your lab
Create a free BvLogic ID to hand in your lab, get it marked, and have it on your certificate.
Create your BvLogic IDAlready have one? Sign in and this course will be added to it.