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

أساسيات PostgreSQL

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

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

نظرة عامة

الموضوعات

  • التثبيت
  • pgAdmin/DBeaver
  • المخططات (schemas)
  • القيود (constraints)
  • CRUD
  • مقدمة في المعاملات (transactions)

تعلّم أولًا

64 دقيقة قراءة · 3 ساعة تدريب (تقدير)

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

  1. Install PostgreSQL and connect with psql and a GUI client (pgAdmin or DBeaver).
  2. Create a database, schema, and user.
  3. Apply NOT NULL, UNIQUE, CHECK, and foreign-key constraints and observe rejected data.
  4. Wrap several statements in a transaction and roll it back.

الدروس

  1. 01تثبيت PostgreSQL11 د قراءة
  2. 02psql وعميل بواجهة رسومية11 د قراءة
  3. 03قواعد البيانات والمخططات والمستخدمون11 د قراءة
  4. 04قيود تحمي البيانات10 د قراءة
  5. 05نظرة أولى على المعاملات (transactions)10 د قراءة
  6. 06عرض عملي: إنشاء قاعدة بيانات Library مع القيود11 د قراءة

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

Lab

BEG-051-LAB1 · Library database live

Outcomes: 1–4 · Time: ~3 h Create the Library schema from BEG-049 as a SQL script with constraints and seed data. Try to insert invalid rows and record the errors. Demonstrate a rollback. Acceptance: script re-runnable from scratch.

Exercises (assessment: practical check of the script)

IDOutcomeTask
BEG-051-EX011Install PostgreSQL, connect with psql, and run SELECT version();.
BEG-051-EX021Connect with pgAdmin or DBeaver and browse the tables of a database.
BEG-051-EX032Create a user library_app, a database library owned by it, and connect as that user.
BEG-051-EX043Add NOT NULL, UNIQUE, and CHECK constraints to books; write one failing insert for each.
BEG-051-EX053Add a foreign key from loans to members and show the error for a missing member.
BEG-051-EX064Run an UPDATE inside BEGIN, check the result, then ROLLBACK and check again.
BEG-051-EX072Explain why an application should not connect as postgres.
أظهر الحلول
  • EX01 psql -U postgres, then SELECT version();.
  • EX02 Register a server on localhost:5432, open Schemas > public > Tables.
  • EX03 CREATE USER library_app WITH PASSWORD '...'; CREATE DATABASE library OWNER library_app; then psql -U library_app -d library.
  • EX04 Null title -> NOT NULL error; repeated ISBN -> unique violation; copies = -1 -> check violation.
  • EX05 member_id INTEGER NOT NULL REFERENCES members(id); inserting member_id = 999 fails with a foreign key violation.
  • EX06 Before rollback the changed value shows; after rollback it is back to the original.
  • EX07 The superuser can change or drop everything; least privilege limits damage from bugs or leaks.

الاختبار

Outcomes: O1 install and connect · O2 database, schema, user · O3 constraints · O4 transactions.

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

  1. 1The command-line client for PostgreSQL is:O1
  2. 2The default PostgreSQL port is:O1
  3. 3In psql, \dt lists:O1
  4. 4An application should connect as:O2
  5. 5The default schema name is:O2
  6. 6To forbid duplicate ISBNs:O3
  7. 7To forbid negative copies:O3
  8. 8An insert with a non-existent member id is rejected by:O3
  9. 9ROLLBACK will:O4
  10. 10Constraints in the database matter because:O4

الجزء العملي

Practical check of the re-runnable schema script with constraints, recorded errors, and a demonstrated rollback (lab and EX01–EX07). Pass: script runs from scratch, at least 8 of 10 quiz questions.

أخطاء شائعة

Working as the postgres superuser; constraints only in application code.

التقييم

Practical check of the script.

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

Primary database for the whole curriculum.

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