انتقل إلى المحتوى
أمين أبوزيد
BEG-050

أساسيات SQL

  • 9 درس
  • 101 دقيقة قراءة
  • 6 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

نظرة عامة

الموضوعات

  • DDL
  • DML
  • SELECT
  • WHERE
  • ORDER BY
  • GROUP BY
  • HAVING
  • JOINs
  • الاستعلامات الفرعية (subqueries)

تعلّم أولًا

101 دقيقة قراءة · 6 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Create and alter tables with DDL.
  2. Insert, update, and delete rows with DML, always with a correct WHERE.
  3. Query with SELECT, WHERE, ORDER BY, GROUP BY, HAVING, and aggregates.
  4. Combine tables with inner and left joins and explain the difference.
  5. Use a subquery where it is clearer than a join.

الدروس

  1. 01نظرة عامة على SQL: DDL مقابل DML11 د قراءة
  2. 02CREATE وALTER12 د قراءة
  3. 03INSERT وUPDATE وDELETE11 د قراءة
  4. 04SELECT وWHERE وORDER BY10 د قراءة
  5. 05دوال التجميع وGROUP BY وHAVING10 د قراءة
  6. 06الربط (Joins)12 د قراءة
  7. 07الاستعلامات الفرعية (Subqueries)12 د قراءة
  8. 08عرض عملي: الإجابة عن أسئلة المكتبة باستخدام SQL11 د قراءة
  9. 09عرض عملي: joins تُسقط الصفوف بصمت12 د قراءة

المختبر والتمارين

Lab

BEG-050-LAB1 · Library queries

Outcomes: 1–5 · Time: ~6 h Answer 25 graded queries against a seeded library database: overdue loans, most-borrowed authors, members with no loans, and more. Acceptance: 20 of 25 correct.

Exercises (assessment: timed SQL test, also part of the BEG graduation gate)

IDOutcomeTask
BEG-050-EX011Create a publishers table (id, name, city) and add a website column afterwards.
BEG-050-EX022Insert two publishers, update one city, delete the other, each with a correct WHERE.
BEG-050-EX033List books from after 1990, newest first, at most five of them (ties in year broken by title).
BEG-050-EX043Count books per author and keep only authors with at least two.
BEG-050-EX054List every member and their loans, including members with no loans.
BEG-050-EX064Explain in two sentences the difference between inner and left join.
BEG-050-EX075List titles of books never loaned, using a subquery.
BEG-050-EX082Explain why you run a SELECT before an UPDATE and what a missing WHERE does.
أظهر الحلول
  • EX01 CREATE TABLE publishers (id INTEGER PRIMARY KEY, name TEXT NOT NULL, city TEXT); ALTER TABLE publishers ADD COLUMN website TEXT;
  • EX02 INSERT ... VALUES (...); UPDATE publishers SET city = 'Oslo' WHERE id = 1; DELETE FROM publishers WHERE id = 2;
  • EX03 SELECT title FROM books WHERE published_year > 1990 ORDER BY published_year DESC, title LIMIT 5; LIMIT 5 means at most five rows: fewer qualify, fewer come back. The second sort key (title) makes the order of books from the same year predictable.
  • EX04 SELECT author_id, COUNT(*) FROM books GROUP BY author_id HAVING COUNT(*) >= 2;
  • EX05 SELECT m.name, l.id FROM members m LEFT JOIN loans l ON l.member_id = m.id;
  • EX06 Inner join keeps only matched rows; left join keeps all left rows and fills missing right columns with NULL.
  • EX07 SELECT title FROM books WHERE id NOT IN (SELECT book_id FROM loans); (this works if loans.book_id has no NULLs).
  • EX08 The SELECT shows which rows will change; without WHERE every row is changed.

الاختبار

Outcomes: O1 DDL · O2 DML · O3 queries and aggregates · O4 joins · O5 subqueries.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1Which is DDL?O1
  2. 2To add a column to an existing table:O1
  3. 3DELETE FROM books; does what?O2
  4. 4To change one row you need:O2
  5. 5Sort newest first:O3
  6. 6Find rows with an empty return date:O3
  7. 7Filtering on COUNT(*) > 3 belongs in:O3
  8. 8Which keeps all members, even with no loans?O4
  9. 9An inner join can silently:O4
  10. 10WHERE id IN (SELECT ...) uses a:O5

الجزء العملي

Timed SQL test plus the 25-query lab (EX01–EX08). Pass: 20 of 25 lab queries correct and at least 8 of 10 quiz questions.

أخطاء شائعة

UPDATE without WHERE; WHERE on aggregates instead of HAVING; inner join silently dropping rows.

التقييم

Timed SQL test (also part of the BEG graduation gate).

الصلة بالمسار الوظيفي

SQL mastery (MID-011) and every data-access module.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.