Chapterبەش 6 · Lectureوانە 6.1
The Database Development Life Cycleسووڕی ژیانی گەشەپێدانی بنکەدراوە
The eight steps that take a database from an idea to a working system: planning, analysis, conceptual, logical and physical design, implementation and data loading, testing, and deployment and maintenance. With two added skills: turning an E-R diagram into tables, and choosing indexes.
ئەو هەشت هەنگاوەی لە بیرۆکەیەکەوە دەگەیەننە سیستەمێکی کارا: ، ، ، و ، و ، ، و . لەگەڵ دوو کارامەیی زیادکراو: گۆڕینی بۆ و هەڵبژاردنی .
What you will learnچی فێر دەبیت
- Name the eight steps of the database development life cycle in order and say what each one produces.
- Explain the difference between conceptual, logical and physical design.
- Turn a simple E-R diagram into tables with primary and foreign keys.
- Explain what an index is, why it makes searches fast and what it costs.
- Describe what happens in implementation, testing, deployment and maintenance.
- هەشت هەنگاوەکەی بە ڕیز ناو ببەیت و بڵێیت هەر یەکێکیان چی بەرهەم دەهێنێت.
- جیاوازیی نێوان ، و ڕوون بکەیتەوە.
- سادە بگۆڕیت بۆ لەگەڵ و .
- ڕوونی بکەیتەوە چییە، بۆچی گەڕان خێرا دەکات و چ تێچوویەکی هەیە.
- باسی ئەوە بکەیت لە ، ، و چی ڕوودەدات.
Why follow a life cycle?بۆچی پێویستمان بە سووڕی ژیانی بنکەدراوە هەیە؟
Every database you use, at a bank, a hospital or your university, was built step by step. The database development life cycle (DDLC) is that path. It includes all the steps that guide us through the creation of a new database, from the first idea to a system that people use every day. Put another way, it is a process used in development to guide the creation of a database.
هەر کە بەکاری دەهێنیت، لە بانکێک، نەخۆشخانەیەک یان زانکۆکەت، هەنگاو بە هەنگاو دروست کراوە. (DDLC) ئەو ڕێگایەیە. هەموو ئەو هەنگاوانە لەخۆ دەگرێت کە لە دروستکردنی نوێدا ڕێنماییمان دەکەن، لە یەکەم بیرۆکەوە تا سیستەمێک کە خەڵک ڕۆژانە بەکاری دەهێنن. بە واتایەکی تر، پرۆسەیەکە لە گەشەپێداندا بەکاردێت بۆ ئەوەی ڕێنمایی دروستکردنی بکات.
Building a house in Erbil follows the same path. You decide how big it will be and what you can spend (planning). You ask the family what they need: how many bedrooms, a guest room, a garden (analysis). An architect draws a rough sketch, then exact room plans, then the engineer's construction drawings (the three design steps). Builders put it up and the furniture is moved in (implementation and loading). Someone checks the water, the power and the doors (testing). Then the family lives there and repairs things for years (deployment and maintenance).
دروستکردنی خانوویەک لە هەولێر هەمان ڕێگا دەگرێتەبەر. بڕیار دەدەیت چەند گەورە بێت و چەندی تێدەچێت (). لە خێزانەکە دەپرسیت چییان پێویستە: چەند ژووری نوستن، ژووری میوان، باخچە (). ئەندازیاری تەلارسازی سەرەتا وێنەیەکی سەرەتایی دەکێشێت، پاشان نەخشەی وردی ژوورەکان، پاشان نەخشەی بیناسازی بۆ وەستاکان (سێ هەنگاوەکەی دیزاین). وەستاکان خانووەکە دروست دەکەن و کەلوپەل دەگوازرێتەوە ناوی ( و ). کەسێک ئاو، کارەبا و دەرگاکان دەپشکنێت (). پاشان خێزانەکە چەندین ساڵ تێیدا دەژین و چاکی دەکەنەوە ( و ).
Where the analogy stops workingسنووری ئەم نموونەیە
A house is finished once. A database keeps changing, so its life cycle starts again whenever new needs appear.
خانوو یەک جار تەواو دەبێت. بەردەوام دەگۆڕێت، بۆیە هەر کاتێک پێویستیی نوێ دەرکەوت، هەنگاوەکان دووبارە دەست پێدەکەنەوە.
In this lesson: what the life cycle is, planning and analysis, the three design stages (conceptual, logical and physical), and implementation, testing and deployment.
لەم وانەیەدا: چییە، و ، سێ قۆناغەکەی دیزاین (چەمکی، لۆجیکی و فیزیکی) و ، و .
The eight stepsهەشت هەنگاوەکە
The whole process has eight steps. Each step uses what the step before it produced.
هەموو پرۆسەکە هەشت هەنگاوە. هەر هەنگاوێک ئەوە بەکاردەهێنێت کە هەنگاوی پێشووی بەرهەمی هێناوە.
- Planning: agree the goal, the size of the project (its scope) and the standards.
- Analysis: collect the requirements and write the requirement specifications.
- Conceptual design: draw the entities and their relationships (an E-R diagram).
- Logical design: add every attribute, the keys, normalization and the integrity rules.
- Physical design: turn the design into real tables, columns and data types for one particular DBMS.
- Implementation and data loading: create the empty tables, then fill them with the real data.
- Testing: try to break it on purpose, before it reaches its users.
- Deployment and maintenance: put it into real use, then keep it monitored, backed up, tuned and secure.
- : ڕێککەوتن لەسەر ئامانج، قەبارەی پڕۆژەکە () و ستانداردەکان.
- : کۆکردنەوەی و نووسینی .
- : کێشانی و ().
- : زیادکردنی هەموو ، ، و .
- : دیزاینەکە دەکرێتە ، و بۆ دیاریکراو.
- و : دروستکردنی بە بەتاڵی، پاشان پڕکردنەوەیان بە ڕاستەقینە.
- : بە ئەنقەست هەوڵی تێکدانی بدە، پێش ئەوەی بگاتە دەستی .
- و : خستنە بەکارهێنانی ڕاستەقینە، پاشان چاودێریکردن، گرتنی ، باشترکردنی خێرایی و پاراستنی بەردەوام.
Step 1: Planningهەنگاوی ١: پلاندانانی بنکەدراوە
Planning creates the foundation for the final database, before anything is built. A written plan helps the project go smoothly and prevents scope problems and errors later.
بناغەی دادەنێت، پێش ئەوەی هیچ شتێک دروست بکرێت. پلانێکی نووسراو یارمەتی دەدات پڕۆژەکە بە ئاسانی بڕوات و ڕێگری لە کێشەی و هەڵەی دواتر دەکات.
Planning should also set standards: written rules that everyone on the project follows. They say:
دەبێت ستانداردەکانیش دابنێت: یاسای نووسراو کە هەموو کەسێکی ناو پڕۆژەکە پەیڕەویان دەکات. ئەم ستانداردانە دەڵێن:
- how the data will be collected (for example from paper forms, an old Excel file or a web form);
- how the format of each item is specified (for example dates always as YYYY-MM-DD, phone numbers without spaces);
- how design and implementation will proceed: who does each job, with which tools and in which order.
- چۆن کۆ دەکرێتەوە (بۆ نموونە لە فۆڕمی کاغەزی، فایلێکی کۆنی Excel یان فۆڕمێکی سەر وێب)؛
- فۆرماتی هەر بڕگەیەک چۆن دیاری دەکرێت (بۆ نموونە ڕێکەوت هەمیشە بە شێوەی YYYY-MM-DD، ژمارەی مۆبایل بەبێ بۆشایی)؛
- دیزاین و جێبەجێکردن چۆن بەڕێوە دەچن: کێ هەر کارێک دەکات، بە چ ئامرازێک و بە چ ڕیزبەندییەک.
How big a project is: what it will include and what it will not. Agreeing the scope early stops the work from growing without end.
قەبارەی پڕۆژەیەکە: چی دەگرێتەوە و چی ناگرێتەوە. ڕێککەوتن لەسەر مەوداکە لە سەرەتادا ڕێگە نادات کارەکە بێکۆتا گەورە ببێت.
'Scope' means how big the project is: what is inside it and what is not. Agreeing it early stops the job growing without end.
واتە پڕۆژەکە چەند گەورەیە: چی دەکەوێتە ناویەوە و چی ناکەوێتە ناویەوە. ڕێککەوتن لەسەری لە سەرەتاوە ڕێگری دەکات لەوەی کارەکە بێکۆتایی گەورە ببێت.
Example. A school wants a library database. In scope: books, students, classes and loans. Out of scope: staff salaries and exam marks. If someone asks for marks halfway through, that is either a new project or a planned change to this one, decided on purpose.
نموونە. قوتابخانەیەک کتێبخانەی دەوێت. لە ناو : کتێب، قوتابی، پۆل و خواستنی کتێب. لە دەرەوەی: مووچەی ستاف و نمرەی تاقیکردنەوە. ئەگەر کەسێک لە نیوەی کارەکەدا داوای نمرەکان بکات، ئەوە یان پڕۆژەیەکی نوێیە یان گۆڕانکارییەکی پلاندارێژراوە کە بە ئەنقەست بڕیاری لەسەر دەدرێت.
Step 2: Analysisهەنگاوی ٢: شیکردنەوەی پێداویستییەکان
Analysis is also called requirement gathering. It is the process of collecting and analysing information about the part of the organisation that the database will support.
بە هەندێک جار دەوترێت کۆکردنەوەی . ئەم هەنگاوە بریتییە لە کۆکردنەوە و شیکردنەوەی دەربارەی ئەو بەشەی دامەزراوەکە کە خزمەتی دەکات.
This step finds every task the database will perform and every use case: a short description of one thing a user does with the system, such as 'a librarian lends a book to a student'.
ئەم هەنگاوە هەموو ئەو کارانە دیاری دەکات کە ئەنجامیان دەدات، لەگەڵ هەموو : وەسفێکی کورتی یەک کارە کە بە سیستەمەکە دەیکات، وەک «کتێبدار کتێبێک دەداتە قوتابییەک».
The written document that lists everything the database must store and do. Every later step is checked against it.
ئەو بەڵگەنامە نووسراوەیە کە هەموو ئەو شتانەی تێدا ڕیز کراوە کە بنکەدراوەکە دەبێت هەڵیانبگرێت و بیانکات. هەموو هەنگاوەکانی دواتر لەگەڵیدا بەراورد دەکرێن.
Everything gathered in this step is stored in this document. It is the written list of everything the database must do. Every later step is checked against it, so it has to be right.
هەموو ئەوەی لەم هەنگاوەدا کۆ دەکرێتەوە لەم بەڵگەنامەیەدا هەڵدەگیرێت. لیستی نووسراوی هەموو ئەو شتانەیە کە دەبێت بیکات. هەموو هەنگاوەکانی دواتر لەگەڵیدا بەراورد دەکرێن، بۆیە دەبێت دروست بێت.
- Store every book with its title, authors and number of copies.
- Store every student with their name, class and phone numbers.
- Record each loan: which student, which book, the date it was lent and the date it came back.
- A student may borrow at most three books at a time.
- The librarian must be able to see every loan that is more than 14 days late.
- هەموو کتێبێک لەگەڵ ناونیشان، نووسەران و ژمارەی دانەکانی هەڵبگیرێت.
- هەموو قوتابییەک لەگەڵ ناو، پۆل و ژمارە مۆبایلەکانی هەڵبگیرێت.
- هەر خواستنێک تۆمار بکرێت: کام قوتابی، کام کتێب، ڕێکەوتی دانی کتێبەکە و ڕێکەوتی گەڕانەوەی.
- قوتابییەک لە یەک کاتدا دەتوانێت زۆرترین سێ کتێب بخوازێت.
- کتێبدار دەبێت بتوانێت هەموو ئەو خواستنانە ببینێت کە زیاتر لە ١٤ ڕۆژ دواکەوتوون.
Step 2: Analysisهەنگاوی ٢: شیکردنەوەی پێداویستییەکان
What analysis produces: forms, reports, screens and rulesبەرهەمەکانی شیکردنەوەی پێداویستییەکان: فۆرم، ڕاپۆرت، شاشە و ڕێسا
Analysis ends with four concrete products, all made from interviews with the users before any table is designed. For a small mobile-phone shop in Erbil:
بە چوار بەرهەمی دیار کۆتایی دێت، هەموویان لە چاوپێکەوتن لەگەڵ دروست دەکرێن، پێش ئەوەی هیچ دیزاین بکرێت. بۆ دووکانێکی بچووکی مۆبایل لە هەولێر:
| Productبەرهەم | In the phone shopلە دووکانی مۆبایلەکەدا |
|---|---|
| Input documents: every form the business fills inفۆرمەکان: هەر فۆرم یان پەڕەیەک کە کارەکە پڕی دەکاتەوە | the sale invoice (with a printed number), the repair formپسوولەی فرۆشتن (بە ژمارەیەکی چاپکراو)، فۆرمی چاککردنەوە |
| Routine reports: what it must print or see regularlyڕاپۆرتە ئاساییەکان: ئەوەی دەبێت بە بەردەوامی چاپی بکات یان ببینێت | today's sales, phones in stock, repairs waiting, monthly sales per salespersonفرۆشی ئەمڕۆ، مۆبایلەکانی ناو کۆگا، چاککردنەوە چاوەڕوانەکان، فرۆشی مانگانەی هەر فرۆشیارێک |
| Screens for routine jobs (transaction screens): a sketch of eachشاشەکانی کاری ڕۆژانە: وێنەیەکی سادەی هەر یەکێکیان | add a phone, sell a phone (prints a receipt), register a repairزیادکردنی مۆبایلێک، فرۆشتنی مۆبایلێک (پسوولە چاپ دەکات)، تۆمارکردنی چاککردنەوەیەک |
| Assumptions: the business rules, as a listگریمانەکان: ڕێساکانی کارەکە، وەک لیستێک | every phone has a unique IMEI number; a phone is sold only once; prices are in IQD; a customer may buy many phonesهەر مۆبایلێک ژمارەیەکی IMEIـی یەکتای هەیە؛ مۆبایلێک تەنها یەک جار دەفرۆشرێت؛ نرخەکان بە دینارن؛ کڕیارێک دەتوانێت چەند مۆبایلێک بکڕێت |
Each assumption later becomes a key or a constraint: 'a unique IMEI' becomes the primary key of phones; 'sold only once' becomes a UNIQUE rule in sales.
هەر گریمانەیەک دواتر دەبێتە یان : «IMEIـی یەکتا» دەبێتە phones؛ «تەنها یەک جار دەفرۆشرێت» دەبێتە ڕێسای UNIQUE لە salesـدا.
Steps 3 to 5: Designهەنگاوەکانی ٣ تا ٥: دیزاین
Design is the process of creating a design for a database that will support the required system. It consists of three parts, and each part adds detail:
دیزاین پرۆسەی دروستکردنی دیزاینێکە بۆ کە پشتگیری سیستەمی داواکراو بکات. لە سێ بەش پێکدێت و هەر بەشێک وردەکاریی زیاتر زیاد دەکات:
| Stageقۆناغ | The question it answersئەو پرسیارەی وەڵامی دەداتەوە | What it producesچی بەرهەم دەهێنێت |
|---|---|---|
| 1. Conceptual design١. | What things do we store, and how are they linked?چ شتێک هەڵدەگرین و چۆن پێکەوە بەستراون؟ | An E-R diagram |
| 2. Logical design٢. | What exactly does each thing look like?هەر شتێک بە وردی چۆنە؟ | Tables with every attribute, the keys and the rules (not yet tied to one DBMS) لەگەڵ هەموو ، و ڕێساکان (هێشتا بە یەک نەبەستراوە) |
| 3. Physical design٣. | How will a real DBMS store it? ڕاستەقینە چۆن هەڵیدەگرێت؟ | CREATE TABLE statements with data types and indexes, for one DBMS لەگەڵ و ، بۆ یەک |
Steps 3 to 5: Designهەنگاوەکانی ٣ تا ٥: دیزاین
Conceptual designدیزاینی چەمکی
In the conceptual step, the requirement specifications are translated into a conceptual model of the database: a picture that shows the entities that are needed and the relationships between them.
لە هەنگاوی چەمکیدا، وەردەگێڕدرێتە سەر بۆ : وێنەیەک کە پیشان دەدات، لەگەڵ نێوانیان.
The model covers the whole database, but it is not very detailed. The goal is to see the entities, their attributes and the connections between them clearly.
مۆدێلەکە هەموو دەگرێتەوە، بەڵام زۆر ورد نییە. ئامانج ئەوەیە ، و نێوانیان بە ڕوونی ببینرێن.
Example. For the school library, the conceptual model has three entities: Class, Student and Book. A class has many students (one-to-many). A student borrows many books during the year, and a book is borrowed by many students (many-to-many).
نموونە. بۆ کتێبخانەی قوتابخانەکە، سێ هەیە: Class (پۆل)، Student (قوتابی) و Book (کتێب). پۆلێک چەندین قوتابیی هەیە (). قوتابییەک لە ماوەی ساڵدا چەندین کتێب دەخوازێت و کتێبێکیش چەندین قوتابی دەیخوازن ().
Steps 3 to 5: Designهەنگاوەکانی ٣ تا ٥: دیزاین
Logical designدیزاینی لۆجیکی
Logical design fills the sketch in with detail. In this step we specify:
وردەکاری دەخاتە ناو وێنە سەرەتاییەکەوە. لەم هەنگاوەدا ئەمانە دیاری دەکەین:
- All attributes for each entity: every entity in the conceptual model gets its full list of attributes.
- Primary keys, foreign keys and relationships: the keys that identify rows and join tables are decided here. See Database keys.
- Normalizing the database: arranging the tables so that no fact is stored twice. See Normalization.
- Applying integrity constraints: the rules that stop wrong data ever being saved, for example 'every loan must point to a book that exists'.
- هەموو هەر : هەر لە لیستی تەواوی وەردەگرێت.
- ، و : ئەو دەناسێننەوە و پێکەوە دەبەستنەوە لێرەدا بڕیاریان لەسەر دەدرێت. بڕوانە کلیلەکانی بنکەدراوە.
- : ڕێکخستنی بە شێوەیەک کە هیچ ڕاستییەک دوو جار هەڵنەگیرێت. بڕوانە نۆرماڵکردن.
- جێبەجێکردنی : ئەو ڕێسایانەی ڕێگە نادەن هەڵە هەرگیز پاشەکەوت بکرێت، بۆ نموونە «هەر خواستنێک دەبێت ئاماژە بە کتێبێک بکات کە بوونی هەیە».
A logical design is still not tied to one product: the same design could be built in MySQL, SQL Server or PostgreSQL. That choice is made in the next step.
هێشتا بە یەک بەرهەمەوە نەبەستراوە: هەمان دیزاین دەتوانرێت لە MySQL، SQL Server یان PostgreSQL دروست بکرێت. ئەم هەڵبژاردنە لە هەنگاوی دواتردا دەکرێت.
Steps 3 to 5: Designهەنگاوەکانی ٣ تا ٥: دیزاین
From E-R diagram to tablesلە هێڵکاریی قەوارە و پەیوەندییەوە بۆ خشتەکان
| In the E-R diagramلە | In the tablesلە |
|---|---|
| An entity set, e.g. Student، وەک Student | A table. Each simple attribute becomes a column; the key attribute becomes the primary key.. هەر دەبێت بە ؛ دەبێت بە . |
| A composite attribute, e.g. Name = first + last، وەک Name = یەکەم + کۆتایی | One column for each part: first_name, last_name.بۆ هەر بەشێک : first_name، last_name. |
| A multi-valued attribute, e.g. a student's phone numbers، وەک ژمارە مۆبایلەکانی قوتابییەک | A table of its own: the owner's key plus the value, e.g. student_phones(student_id, phone). تایبەت بە خۆی: خاوەنەکە لەگەڵ بەهاکە، وەک student_phones(student_id, phone). |
| A one-to-many relationship, e.g. a Class has many Students، وەک پۆلێک چەندین قوتابیی هەیە | No new table. The 'many' side gets a foreign key that points to the 'one' side, e.g. students.class_id. نوێ نییە. لایەنی «زۆر» وەردەگرێت کە ئاماژە بە لایەنی «یەک» دەکات، وەک students.class_id. |
| A many-to-many relationship, e.g. a Student borrows Books، وەک قوتابی کتێب دەخوازێت | A junction table that holds both keys, plus the relationship's own attributes, e.g. loans(student_id, book_id, loan_date, return_date). کە هەردوو هەڵدەگرێت، لەگەڵ خودی ، وەک loans(student_id, book_id, loan_date, return_date). |
Turns an E-R diagram into tables step by step: entities, weak entities, one-to-one, one-to-many and many-to-many relationships.
پلەبەپلە دەگۆڕێت بۆ : ، ، ، و .
Whole video: the mapping rules on this screen, applied to a company database.
هەموو ڤیدیۆکە: ڕێساکانی گۆڕینی سەر ئەم شاشەیە، لەسەر کۆمپانیایەک جێبەجێ کراون.
Steps 3 to 5: Designهەنگاوەکانی ٣ تا ٥: دیزاین
The library, from diagram to tablesکتێبخانەکە، لە هێڵکارییەوە بۆ خشتەکان
classes (class_id PK, class_name)
students (student_id PK, first_name, last_name, class_id FK -> classes)
student_phones (student_id FK -> students, phone)
PK = student_id + phone
books (book_id PK, title)
loans (student_id FK -> students, book_id FK -> books, loan_date, return_date)
PK = student_id + book_id + loan_dateExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
One-to-many:
class_idis a foreign key on the 'many' side.:
class_idلە لایەنی «زۆر».- Lineدێڕی 3-4
Multi-valued attribute: a table of its own. A student with two phones has two rows.
: جیا. قوتابییەک بە دوو مۆبایلەوە دوو دەبێت.
- Lineدێڕی 6-7
Many-to-many: the junction table.
loan_dateis in the key so that the same student can borrow the same book again later.return_datestays empty until the book comes back.: .
loan_dateلە ناو بۆ ئەوەی هەمان قوتابی بتوانێت دواتر دووبارە هەمان کتێب بخوازێتەوە.return_dateبەتاڵ دەمێنێتەوە تا کتێبەکە دەگەڕێتەوە.
Three more rules: a one-to-one relationship becomes a foreign key on either side, marked UNIQUE. A weak entity's table also holds its owner's key, which becomes part of its primary key. A derived attribute such as age is usually not stored at all, because it can be worked out from the date of birth.
سێ ڕێسای تر: دەبێت بە لە هەر یەک لە دوو لایەنەکە، بە نیشانەی UNIQUE. خاوەنەکەشی هەڵدەگرێت و ئەو دەبێت بە بەشێک لە . وەک تەمەن زۆربەی جار هەر هەڵناگیرێت، چونکە لە ڕێکەوتی لەدایکبوونەوە دەژمێردرێت.
The enhanced E-R model adds recursive, ternary and ISA (specialisation) relationships. For their rules, see From EER to tables.
، و پەیوەندیی ISA () زیاد دەکات. بۆ یاساکانیان بڕوانە لە EERـەوە بۆ خشتەکان.
Steps 3 to 5: Designهەنگاوەکانی ٣ تا ٥: دیزاین
Test the draft tables with sample rowsخشتە سەرەتاییەکان بە ڕیزی نموونەیی تاقی بکەرەوە
Before you build anything, type four or five invented rows into each draft table, on paper or in a spreadsheet. Sample rows show mistakes that a diagram hides:
پێش ئەوەی هیچ شتێک دروست بکەیت، چوار یان پێنج دروستکراو لە هەر سەرەتاییدا بنووسە، لەسەر کاغەز یان لە . نموونەییەکان ئەو هەڵانە پیشان دەدەن کە دەیانشارێتەوە:
- Two students called Aram Kamal in the same class: without a
student_idnobody can tell them apart. - Columns
book1,book2,book3: a fourth loan has nowhere to go. - Many empty cells: the column probably belongs in another table.
- One city typed as Hawler, Erbil and Arbil: three spellings of one fact.
- دوو قوتابی بە ناوی ئارام کەمال لە هەمان پۆلدا: بەبێ
student_idکەس ناتوانێت لێکیان جیا بکاتەوە. -
book1،book2وbook3: خواستنی چوارەم شوێنی نییە. - زۆر خانەی بەتاڵ: ئەو لەوانەیە هی تر بێت.
- یەک شار بە سێ شێوە نووسراوە، Hawler، Erbil و Arbil: سێ ڕێنووس بۆ یەک ڕاستی.
Fix the design and test again. Then show the tables to the users: are the table and column names clear to them, and is anything missing?
دیزاینەکە چاک بکە و دووبارە تاقی بکەرەوە. پاشان پیشانی بدە: ئایا ناوی و بۆیان ڕوونە و ئایا شتێک کەمە؟
Steps 3 to 5: Designهەنگاوەکانی ٣ تا ٥: دیزاین
Physical designدیزاینی فیزیکی
Physical design is the last step of the design phase. It starts tying the model to one real database management system, such as MySQL. You focus on:
دوا هەنگاوی قۆناغی دیزاینە. دەست دەکات بە بەستنەوەی مۆدێلەکە بە ڕاستەقینەوە، وەک MySQL. سەرنج دەخەیتە سەر:
- converting your entities into tables;
- assigning a data type to every column, for example
INT,VARCHAR(50)orDATE; - following the naming conventions of your database system;
- optimising and validating the design before implementation, for example choosing indexes (next screen).
- گۆڕینی بۆ ؛
- دانانی بۆ هەر ، بۆ نموونە
INT،VARCHAR(50)یانDATE؛ - پەیڕەوکردنی یاساکانی ناونان لە سیستەمی ؛
- باشترکردن و پشکنینی دیزاینەکە پێش جێبەجێکردن، بۆ نموونە هەڵبژاردنی (شاشەی دواتر).
CREATE TABLE classes (
class_id INT PRIMARY KEY,
class_name VARCHAR(20) NOT NULL
);
CREATE TABLE students (
student_id INT PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
class_id INT NOT NULL,
FOREIGN KEY (class_id) REFERENCES classes (class_id)
);
CREATE TABLE books (
book_id INT PRIMARY KEY,
title VARCHAR(200) NOT NULL
);
CREATE TABLE loans (
student_id INT NOT NULL,
book_id INT NOT NULL,
loan_date DATE NOT NULL,
return_date DATE,
PRIMARY KEY (student_id, book_id, loan_date),
FOREIGN KEY (student_id) REFERENCES students (student_id),
FOREIGN KEY (book_id) REFERENCES books (book_id)
);Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2-3
Each column gets a data type.
NOT NULLmeans the value is required.هەر وەردەگرێت.
NOT NULLواتە بەهاکە پێویستە.- Lineدێڕی 11
The one-to-many relationship becomes a real foreign key: the DBMS will refuse a
class_idthat does not exist.دەبێت بە ڕاستەقینە: ڕێگە بە
class_idێک نادات کە بوونی نییە.- Lineدێڕی 19-27
The junction table. Its primary key has three columns (a composite key).
. سێ هەیە ().
- Lineدێڕی 23
No
NOT NULLhere:return_datestays empty (NULL) while the book is still out.لێرەدا
NOT NULLنییە:return_dateتا کتێبەکە لە دەرەوەیە بەتاڵ (NULL) دەمێنێتەوە.
Steps 3 to 5: Designهەنگاوەکانی ٣ تا ٥: دیزاین
Choosing column types: a checklistهەڵبژاردنی جۆری ستوونەکان: لیستێکی پشکنین
- Names and addresses:
VARCHARwith room to spare; the longest real name decides the size, not the average one. - Fixed codes only get
CHAR, such asCHAR(3)forIQD. Even codes can grow: storing years with two digits caused the 'year 2000' problem. - Phone numbers are text, not numbers:
+964 750 000 0000has a plus sign and spaces, and nobody adds phone numbers together. - Kurdish text needs a Unicode character set:
utf8mb4, the default in MySQL 8. The old default,latin1, cannot store Kurdish letters. - Column names without spaces, such as
first_name(see the previous screen); a form can still show a friendly label such as First name.
- ناو و ناونیشان:
VARCHARبە شوێنی زیادەوە؛ درێژترین ناوی ڕاستەقینە قەبارەکە دیاری دەکات، نەک ناوی ناوەند. - تەنها کۆدی جێگیر
CHARوەردەگرێت، وەکCHAR(3)بۆIQD. کۆدیش دەتوانێت گەورە بێت: هەڵگرتنی ساڵ بە دوو کێشەی «ساڵی ٢٠٠٠»ـی دروست کرد. - ژمارەی مۆبایل دەقە، نەک ژمارە:
+964 750 000 0000هێمای کۆ و بۆشایی تێدایە و کەس ژمارەی مۆبایل کۆ ناکاتەوە. - دەقی کوردی پێویستی بە هەیە:
utf8mb4، کە لە MySQL 8ـدا بنەڕەتییە.latin1، کە پێشتر بنەڕەتی بوو، ناتوانێت پیتی کوردی هەڵبگرێت. - ناوی بێ بۆشایی، وەک
first_name(شاشەی پێشوو ببینە)؛ هێشتا دەتوانێت ناونیشانێکی ئاسان وەک First name پیشان بدات.
Physical design may also bend the normal forms on purpose to make reading faster: store a total that could be calculated, copy a column to save a join, or split a very wide table. Do it only for a query you have measured as too slow, since every copy must be kept up to date (denormalization). Then show the design to the users again: design is a loop, not a straight line.
دەتوانێت بە ئەنقەستیش لە لابدات بۆ ئەوەی خوێندنەوە خێراتر بێت: کۆیەک هەڵبگرێت کە دەکرا بژمێردرێت، کۆپی بکات بۆ ئەوەی نەکرێت، یان زۆر پان بکات بە دوو بەش. تەنها بۆ بیکە کە پێوانەت کردووە و زۆر هێواشە، چونکە هەر کۆپییەک دەبێت نوێ ڕابگیرێت (نۆرماڵنەکردنەوە). پاشان دیزاینەکە دووبارە پیشانی بدەوە: دیزاین ئەڵقەیەکە، نەک هێڵێکی ڕاست.
Steps 3 to 5: Designهەنگاوەکانی ٣ تا ٥: دیزاین
Choosing indexesهەڵبژاردنی پێڕستەکان
To find 'normalization' in a 600-page textbook, you do not read every page. You open the index at the back: the words are in alphabetical order, and each one gives page numbers. A database index works the same way: a sorted list of the values in one column, each pointing to the rows that hold it.
بۆ دۆزینەوەی «normalization» لە کتێبێکی ٦٠٠ لاپەڕەییدا، هەموو لاپەڕەکان ناخوێنیتەوە. پێڕستەکەی کۆتایی کتێبەکە دەکەیتەوە: وشەکان بە ڕیزی ئەلفوبێن و هەر وشەیەک ژمارەی لاپەڕەکانی لەگەڵە. بە هەمان شێوە کار دەکات: لیستێکی ڕیزکراوی بەهاکانی یەک و هەر بەهایەک ئاماژە بەو دەکات کە هەیانە.
Where the analogy stops workingسنووری ئەم نموونەیە
A book's index is printed once. A database index must be updated every time a row is added, changed or deleted, and that takes time.
پێڕستی کتێب یەک جار چاپ دەکرێت. دەبێت هەر جارێک زیاد، گۆڕین یان سڕینەوەی بۆ کرا نوێ بکرێتەوە و ئەمە کاتی دەوێت.
Without an index, the DBMS starts at the first row and reads the whole table to find the matching rows (a full table scan). The bigger the table, the slower this gets. With an index it can jump straight to the right rows. In MySQL most indexes are stored as B-trees, a sorted tree structure that stays fast even with millions of rows. Indexes are part of physical design.
بەبێ ، لە یەکەم دەست پێدەکات و هەموو دەخوێنێتەوە بۆ دۆزینەوەی گونجاوەکان (full table scan). تا گەورەتر بێت، ئەمە هێواشتر دەبێت. بە دەتوانێت ڕاستەوخۆ باز بداتە سەر دروستەکان. لە MySQL زۆربەی وەک B-tree هەڵدەگیرێن: پێکهاتەیەکی درەختئاسای ڕیزکراو کە تەنانەت بە ملیۆنان خێرا دەمێنێتەوە. بەشێکن لە .
EXPLAIN QUERY PLAN SELECT * FROM loans WHERE book_id = 42;
CREATE INDEX idx_loans_book ON loans (book_id);
EXPLAIN QUERY PLAN SELECT * FROM loans WHERE book_id = 42;QUERY PLAN `--SCAN loans QUERY PLAN `--SEARCH loans USING INDEX idx_loans_book (book_id=?)
SCAN = read every row. SEARCH = jump to the matching rows through the index.
SCAN = خوێندنەوەی هەموو . SEARCH = بازدان بۆ گونجاوەکان لە ڕێگەی .
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
EXPLAIN QUERY PLANshows how SQLite will find the rows. MySQL hasEXPLAINfor the same job. The primary key ofloansstarts withstudent_id, so it does not help a search bybook_id.EXPLAIN QUERY PLANپیشان دەدات SQLite چۆن دەدۆزێتەوە. MySQL بۆ هەمان کارEXPLAINـی هەیە.loansبەstudent_idدەست پێدەکات، بۆیە یارمەتی گەڕان بەbook_idنادات.- Lineدێڕی 2
Create an index on the column that the search uses.
لەسەر ئەو دروست بکە کە گەڕانەکە بەکاری دەهێنێت.
- A primary key gets an index automatically (a unique index).
- A foreign key column is often worth indexing, because joins use it. MySQL (InnoDB) creates this index for you if it is missing; SQL Server does not.
- Index the columns that searches and sorting use often.
- Do not index everything. Each index takes extra storage, and every
INSERT,UPDATEandDELETEmust update it too.
- خۆکارانە وەردەگرێت ( یەکتا).
- زۆرجار شایەنی ، چونکە بەستنەوەی بەکاری دەهێنێت. MySQL (InnoDB) ئەگەر نەبێت خۆی دروستی دەکات؛ SQL Server نایکات.
- بکە کە گەڕان و ڕیزکردن زۆر بەکاریان دەهێنن.
- هەموو شتێک مەکە. هەر شوێنی زیادە دەگرێت و هەموو
INSERT،UPDATEوDELETEێک دەبێت ئەویش نوێ بکاتەوە.
Shows a slow search on a big table, then creates an index and a multi-column index and measures the speed-up. Use indexes wisely.
گەڕانێکی هێواش لە گەورەدا پیشان دەدات، پاشان و چەند دروست دەکات و خێرابوونەکە دەپێوێت. بە وریاییەوە بەکار بهێنە.
Whole video: why an index makes searches fast, and how to create one.
هەموو ڤیدیۆکە: بۆچی گەڕان خێرا دەکات و چۆن یەکێک دروست بکەیت.
Steps 3 to 5: Designهەنگاوەکانی ٣ تا ٥: دیزاین
Kinds of index, and why disk reads matterجۆرەکانی پێڕست و بۆچی خوێندنەوە لە دیسکەوە گرنگە
Reading from memory (RAM) is much faster than reading from storage, even from a fast SSD. So a DBMS saves time mainly by reading as few disk blocks as possible, and that is exactly what an index does.
خوێندنەوە لە زۆر خێراترە لە خوێندنەوە لە ، تەنانەت لە خێرا. بۆیە بە زۆری بەوە کات دەپارێزێت کە کەمترین بلۆکی دیسک بخوێنێتەوە و ئەمە ڕێک ئەو کارەیە کە دەیکات.
| Kindجۆر | Good forباشە بۆ | Where you meet itلە کوێ دەیبینیت |
|---|---|---|
| B-tree (B+-tree) | =, <, >, BETWEEN and ORDER BY=، <، >، BETWEEN و ORDER BY | the default in MySQL, PostgreSQL and SQLiteبنەڕەتییە لە MySQL، PostgreSQL و SQLite |
only =: one exact value, very fast; no ranges, no sortingتەنها =: یەک بەهای ورد، زۆر خێرا؛ نە گەڕان لە نێوان دوو بەهادا، نە ڕیزکردن | PostgreSQL (USING HASH), MySQL's MEMORY tablesPostgreSQL (USING HASH)، MEMORYـی MySQL | |
| columns with few different values (city, yes/no) in big reports کەم بەها (شار، بەڵێ/نەخێر) لە ڕاپۆرتە گەورەکاندا | data warehouses, for example Oracle Database، بۆ نموونە Oracle Database |
A table can have only one clustered index, which holds the rows themselves in key order: in MySQL InnoDB that is the primary key. Every other index is a secondary index: it stores the value and a pointer to the row (in InnoDB, the row's primary key). Rows kept in no special order are called a heap.
تەنها دەتوانێت یەک هەبێت، کە خودی بە ڕیزبەندیی هەڵدەگرێت: لە MySQL InnoDB ئەوە . هەر تر : بەهاکە و ئاماژەیەک بۆ هەڵدەگرێت (لە InnoDB، ئەو ). ئەو بە هیچ ڕیزبەندییەکی تایبەت هەڵنەگیراون پێیان دەوترێت heap.
Steps 3 to 5: Designهەنگاوەکانی ٣ تا ٥: دیزاین
The design process: eight steps, not fiveپرۆسەی دیزاین: هەشت هەنگاو، نەک پێنج
The physical design slide also lists a 'design process' in five steps: 1 divide the information into tables; 2 turn information items into columns; 3 set up the table relationships; 4 refine your design; 5 apply the normalization rules.
سلایدی «پرۆسەی دیزاین»یش بە پێنج هەنگاو دەژمێرێت: ١ دابەشکردنی بۆ ؛ ٢ گۆڕینی بڕگەکانی بۆ ؛ ٣ دانانی نێوان ؛ ٤ باشترکردنی دیزاینەکەت؛ ٥ جێبەجێکردنی یاساکانی .
- Determine the purpose of your database. (Planning)
- Find and organize the information required. (Analysis)
- Divide the information into tables. (Conceptual and logical design)
- Turn information items into columns. (Logical design)
- Specify primary keys. (Logical design; missing from the slide)
- Set up the table relationships. (Logical design)
- Refine your design. (Logical and physical design)
- Apply the normalization rules. (Logical design)
- مەبەستی دیاری بکە. ()
- پێویست بدۆزەرەوە و ڕێکی بخە. ()
- دابەش بکە بۆ . ( و )
- بڕگەکانی بکە بە . ()
- دیاری بکە. (؛ لە سلایدەکەدا نییە)
- نێوان دابنێ. ()
- دیزاینەکەت باشتر بکە. ( و )
- یاساکانی جێبەجێ بکە. ()
From an idea to a database design: write the requirements down, find the nouns, make tables, add attributes and relationships, then check and normalize.
لە بیرۆکەیەکەوە تا دیزاینی : نووسینی ، دۆزینەوەی ناوەکان (nouns)، دروستکردنی ، زیادکردنی و ، پاشان پشکنین و .
Whole video: the design steps in practice, close to the eight-step process on this screen.
هەموو ڤیدیۆکە: هەنگاوەکانی دیزاین لە کاردا، نزیک لەو ڕێگا هەشت هەنگاوییەی سەر ئەم شاشەیە.
Step 6: Implementation and data loadingهەنگاوی ٦: جێبەجێکردنی بنکەدراوە و بارکردنی دراوە
Once you are sure that the design is solid, you build the database in the DBMS, load the data that you collected into it, and connect it to the other applications that will use it, for example a website or a school management program.
کاتێک دڵنیا بوویت دیزاینەکە پتەوە، لە ناو دروست دەکەیت، ئەو کۆت کردۆتەوە بار دەکەیتە ناوی و بە بەرنامەکانی ترەوە دەیبەستیتەوە کە بەکاری دەهێنن، بۆ نموونە یان بەرنامەیەکی بەڕێوەبردنی قوتابخانە.
- the same student typed twice: 'Aram Ali' and 'aram ali ';
- dates written in three ways: 5/3/2024, 2024-03-05 and 5 March 2024;
- phone numbers with letters in them or digits missing;
- empty cells where a value is required.
- هەمان قوتابی دوو جار نووسراوە: 'Aram Ali' و 'aram ali '؛
- ڕێکەوت بە سێ شێوە نووسراوە: 5/3/2024، 2024-03-05 و 5 March 2024؛
- ژمارەی مۆبایل کە پیتی تێدایە یان ژمارەی کەمە؛
- خانەی بەتاڵ لە شوێنێکدا کە بەها پێویستە.
Step 7: Testingهەنگاوی ٧: تاقیکردنەوە
Testing is the process of running the database system with the intent of finding errors. The goal is to make sure that everything works as expected. Testing shows that the database and the application programs appear to work according to the requirements.
پرۆسەی کارپێکردنی سیستەمی بە مەبەستی دۆزینەوەی هەڵە. ئامانج ئەوەیە دڵنیا بیت هەموو شتێک وەک چاوەڕوانکراو کار دەکات. پیشانی دەدات کە و بەپێی کار دەکەن.
| Testتاقیکردنەوە | Expected resultئەنجامی چاوەڕوانکراو |
|---|---|
| Lend a book to a student number that does not exist.دانی کتێبێک بە ژمارەی قوتابییەک کە بوونی نییە. | Refused by the foreign key. ڕەتی دەکاتەوە. |
| Save a student with an empty last name.پاشەکەوتکردنی قوتابییەک بە ناوی کۆتایی بەتاڵ. | Refused by NOT NULL.NOT NULL ڕەتی دەکاتەوە. |
| Lend a fourth book to a student who already has three.دانی کتێبی چوارەم بە قوتابییەک کە سێی لایە. | Refused by the application or a database trigger: a rule from the requirement specifications that keys alone cannot check.بەرنامەکە یان ڕەتی دەکاتەوە: ڕێسایەکی کە بە تەنها ناتوانن بیپشکنن. |
| A book title 5,000 characters long.ناونیشانی کتێبێک بە درێژیی ٥٠٠٠ پیت. | Refused (MySQL's default strict mode): the column allows 200 characters.ڕەت دەکرێتەوە (لە دۆخی توندی بنەڕەتیی MySQL): ٢٠٠ پیت ڕێگە دەدات. |
| Find the loans of one book among a million loans.دۆزینەوەی خواستنەکانی یەک کتێب لە ناو ملیۆنێک خواستن. | Fast, because an index is used.خێرا، چونکە بەکاردێت. |
Step 8: Deployment and maintenanceهەنگاوی ٨: خستنەکار و چاککاری
Deployment: once everything is confirmed to be working, the database is deployed to the production environment.
: کاتێک دڵنیا بوویت هەموو شتێک کار دەکات، دەخرێتە ناو ـەوە.
The real system that real users work with every day, as opposed to a test copy. Mistakes there affect real work, so changes are tested first.
ئەو سیستەمە ڕاستەقینەیەیە کە بەکارهێنەرانی ڕاستەقینە هەموو ڕۆژێک کاری لەگەڵ دەکەن، بە پێچەوانەی کۆپییەکی تاقیکردنەوە. هەڵە لەوێ کاری ڕاستەقینە دەگرێتەوە، بۆیە گۆڕانکارییەکان سەرەتا تاقی دەکرێنەوە.
'Production' means the real system that real people use, as opposed to a test copy. Mistakes there affect real work.
واتە ئەو سیستەمە ڕاستەقینەیەی خەڵکی ڕاستەقینە بەکاری دەهێنن، بە پێچەوانەی کۆپیی تاقیکردنەوە. هەڵە لەوێ کاری ڕاستەقینە تێک دەدات.
Maintenance: deployment is not the end. From now on the database has to be monitored, backed up, tuned and kept secure, for as long as the organisation uses it. Backups are taught in Backup and recovery and protection in Database security.
: کۆتایی نییە. لەمەودوا دەبێت چاودێریی بکرێت، لێ بگیرێت، خێراییەکەی باشتر بکرێت و پارێزراو بمێنێتەوە، تا ئەو کاتەی دامەزراوەکە بەکاری دەهێنێت. لە باکئەپ و گەڕاندنەوەی دراوە و پاراستن لە ئاسایشی بنکەدراوە فێر دەبیت.
Common mistakesهەڵە باوەکان
| Mistakeهەڵە | Why it hurtsبۆچی زیان دەگەیەنێت | Do this insteadلە جیاتی ئەوە |
|---|---|---|
Writing CREATE TABLE before talking to the usersنووسینی CREATE TABLE پێش قسەکردن لەگەڵ | The tables miss what users need, so you rebuild later. ئەوەیان تێدا نییە کە پێویستیانە، بۆیە دواتر دووبارە دروستیان دەکەیتەوە. | Do planning and analysis first and write the requirement specifications.سەرەتا و بکە و بنووسە. |
| Letting the project grow without anyone decidingهێشتنەوەی پڕۆژەکە بۆ ئەوەی بەبێ بڕیاری کەس گەورە ببێت | The project never ends.پڕۆژەکە هەرگیز تەواو نابێت. | Agree the scope in planning; treat each new wish as a planned change.لە لەسەر ڕێک بکەون؛ هەر داواکارییەکی نوێ وەک گۆڕانکارییەکی پلاندارێژراو سەیر بکە. |
Storing a many-to-many relationship as a list in one column, e.g. books = '12,40,57'هەڵگرتنی وەک لیستێک لە یەک ، وەک books = '12,40,57' | Hard to search, easy to break, and no foreign key can check it.گەڕان تێیدا قورسە، بە ئاسانی تێکدەچێت و هیچ ناتوانێت بیپشکنێت. | Use a junction table. بەکاربهێنە. |
| Putting an index on every columnدانانی لەسەر هەموو | Writes become slow and storage is wasted.نووسین هێواش دەبێت و شوێنی خەزنکردن بە فیڕۆ دەچێت. | Index the keys and the columns that are searched often. و ئەو بکە کە زۆر گەڕانیان تێدا دەکرێت. |
| Testing only with normal valuesتاقیکردنەوە تەنها بە بەهای ئاسایی | The errors appear later, in real use.هەڵەکان دواتر، لە بەکارهێنانی ڕاستەقینەدا دەردەکەون. | Try empty, strange and very large values.بەهای بەتاڵ، سەیر و زۆر گەورە تاقی بکەرەوە. |
| Testing on the production databaseتاقیکردنەوە لەسەر | Real data can be changed or deleted. ڕاستەقینە دەکرێت بگۆڕدرێت یان بسڕدرێتەوە. | Test on a separate copy.لەسەر کۆپییەکی جیا تاقی بکەرەوە. |
Exercisesڕاهێنانەکان
Write these steps in the right order: Testing; Logical design; Planning; Deployment and maintenance; Conceptual design; Implementation and data loading; Analysis; Physical design.
ئەم هەنگاوانە بە ڕیزبەندیی دروست بنووسە: ؛ ؛ ؛ و ؛ ؛ و ؛ ؛ .
Show answerوەڵامەکە پیشان بدە
- Planning
- Analysis
- Conceptual design
- Logical design
- Physical design
- Implementation and data loading
- Testing
- Deployment and maintenance
- و
- و
For each task in the library project, name the life-cycle step: (a) interview the librarian; (b) decide that title is VARCHAR(200); (c) draw Student – borrows – Book; (d) import 3,000 books from an old spreadsheet; (e) try to lend a book to a student who does not exist; (f) add the foreign key class_id to the students table; (g) agree that staff salaries are out of scope; (h) take a backup every night.
بۆ هەر کارێکی پڕۆژەی کتێبخانەکە، هەنگاوەکەی ناو ببە: (أ) چاوپێکەوتن لەگەڵ کتێبدار؛ (ب) بڕیاردان کە title جۆری VARCHAR(200)ـە؛ (ج) کێشانی Student – borrows – Book؛ (د) هێنانی ٣٠٠٠ کتێب لە خشتەیەکی کۆنی Excelـەوە؛ (هـ) هەوڵدان بۆ دانی کتێب بە قوتابییەک کە بوونی نییە؛ (و) زیادکردنی class_id بۆ students؛ (ز) ڕێککەوتن کە مووچەی ستاف لە دەرەوەی ؛ (ح) گرتنی هەموو شەوێک.
Show answerوەڵامەکە پیشان بدە
- (a) Analysis (requirement gathering)
- (b) Physical design (data types)
- (c) Conceptual design (E-R diagram)
- (d) Implementation and data loading
- (e) Testing
- (f) Logical design (keys and relationships)
- (g) Planning (scope)
- (h) Deployment and maintenance
- (أ) (کۆکردنەوەی )
- (ب) ()
- (ج) ()
- (د) و
- (هـ)
- (و) ( و )
- (ز) ()
- (ح) و
A clinic has these entities: Department (dept_id, name), Doctor (doctor_id, name) and Patient (patient_id, name, and several phone numbers). A department has many doctors; each doctor works in one department. A doctor sees many patients and a patient can see many doctors; each visit has a date. Write the tables with their primary and foreign keys.
لە نۆرینگەیەکدا ئەم سێ هەن: Department (dept_id، name)، Doctor (doctor_id، name) و Patient (patient_id، name و چەند ژمارە مۆبایلێک). بەشێک چەندین دکتۆری هەیە؛ هەر دکتۆرێک لە یەک بەشدا کار دەکات. دکتۆرێک چەندین نەخۆش دەبینێت و نەخۆشێک دەتوانێت چەندین دکتۆر ببینێت؛ هەر سەردانێک ڕێکەوتی هەیە. لەگەڵ و بنووسە.
Hintئاماژە
Find the one-to-many relationship, the many-to-many relationship and the multi-valued attribute first.
سەرەتا ، و بدۆزەرەوە.
Show answerوەڵامەکە پیشان بدە
departments (dept_id PK, name)
doctors (doctor_id PK, name, dept_id FK -> departments)
patients (patient_id PK, name)
patient_phones (patient_id FK -> patients, phone)
PK = patient_id + phone
visits (doctor_id FK -> doctors, patient_id FK -> patients, visit_date)
PK = doctor_id + patient_id + visit_dateExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
One-to-many: the foreign key goes on the 'many' side (doctors).
: دەچێتە لایەنی «زۆر» (doctors).
- Lineدێڕی 4-5
Multi-valued attribute: its own table.
: تایبەت بە خۆی.
- Lineدێڕی 6-7
Many-to-many with an attribute (the date): a junction table.
لەگەڵ (ڕێکەوت): .
You are in the Analysis step for a clinic's appointment system. Write four requirements for the requirement specifications. Each one should be short, testable and say what the database must store or do.
تۆ لە هەنگاوی بۆ سیستەمی ژوانی نۆرینگەیەکیت. چوار بۆ بنووسە. هەر یەکێکیان دەبێت کورت بێت، بتوانرێت تاقی بکرێتەوە و بڵێت دەبێت چی هەڵبگرێت یان چی بکات.
Show answerوەڵامەکە پیشان بدە
- Store every patient with name, date of birth and at least one phone number.
- Store every appointment: patient, doctor, date and time.
- A doctor cannot have two appointments at the same date and time.
- The receptionist must see all of tomorrow's appointments for one doctor.
- هەموو نەخۆشێک لەگەڵ ناو، ڕێکەوتی لەدایکبوون و لانیکەم یەک ژمارە مۆبایل هەڵبگیرێت.
- هەموو ژوانێک هەڵبگیرێت: نەخۆش، دکتۆر، ڕێکەوت و کات.
- دکتۆرێک ناتوانێت دوو ژوانی لە هەمان ڕێکەوت و کاتدا هەبێت.
- پێشوازیکار دەبێت بتوانێت هەموو ژوانەکانی سبەینێی یەک دکتۆر ببینێت.
Exercisesڕاهێنانەکان
More exercises: design it yourselfڕاهێنانی زیاتر: خۆت دیزاینی بکە
Design a small database for a school canteen. Each item (tea, kubba, a sandwich) has a name that is never repeated, a price in IQD and its calories. Each bill has a number that is never reused and a date; it can list several items, each with a quantity. Only items that exist may appear on a bill. Write the tables with their keys, then test them.
بچووک بۆ کافتریای قوتابخانەیەک دیزاین بکە. هەر خواردنێک (چا، کوبە، ساندویچ) ناوێکی هەیە کە هەرگیز دووبارە نابێتەوە، لەگەڵ نرخێک بە دینار و ژمارەی کالۆرییەکەی. هەر پسوولەیەک ژمارەیەک (کە هەرگیز دووبارە بەکار نایەتەوە) و ڕێکەوتێکی هەیە؛ دەتوانێت چەند خواردنێک لیست بکات، هەر یەکە بە بڕێک. تەنها ئەو خواردنانەی بوونیان هەیە دەتوانن لە پسوولەدا بن. لەگەڵ بنووسە، پاشان تاقییان بکەرەوە.
Hintئاماژە
One bill lists many items, and one item appears on many bills. What does that make?
یەک پسوولە چەندین خواردن لیست دەکات و یەک خواردن لە چەندین پسوولەدا دەردەکەوێت. ئەمە چی دروست دەکات؟
Show answerوەڵامەکە پیشان بدە
PRAGMA foreign_keys = ON;
CREATE TABLE items (
item_id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL UNIQUE,
price INT NOT NULL CHECK (price > 0),
calories INT
);
CREATE TABLE bills (
bill_no INT PRIMARY KEY,
bill_date DATE NOT NULL
);
CREATE TABLE bill_items (
bill_no INT NOT NULL,
item_id INT NOT NULL,
quantity INT NOT NULL CHECK (quantity > 0),
PRIMARY KEY (bill_no, item_id),
FOREIGN KEY (bill_no) REFERENCES bills (bill_no),
FOREIGN KEY (item_id) REFERENCES items (item_id)
);
INSERT INTO items VALUES (1, 'Tea', 500, 30), (2, 'Kubba', 1500, 250);
INSERT INTO bills VALUES (1001, '2026-10-25');
INSERT INTO bill_items VALUES (1001, 1, 2), (1001, 2, 1);
INSERT INTO bills VALUES (1001, '2026-10-26');
INSERT INTO bill_items VALUES (1001, 9, 1);
SELECT bi.bill_no, i.name, bi.quantity, bi.quantity * i.price AS total
FROM bill_items bi
JOIN items i ON i.item_id = bi.item_id;Runtime error near line 23: UNIQUE constraint failed: bills.bill_no (19) Runtime error near line 24: FOREIGN KEY constraint failed (19) 1001|Tea|2|1000 1001|Kubba|1|1500
The two errors come from lines 23 and 24; the bill keeps only its two valid lines.
دوو هەڵەکە لە دێڕەکانی 23 و 24ـەوە دێن؛ پسوولەکە تەنها دوو دێڕە دروستەکەی دەمێنێتەوە.
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 4-5
UNIQUEstops a second item with the same name;CHECKstops a price of zero.UNIQUEڕێگە لە خواردنی دووەم بە هەمان ناو دەگرێت؛CHECKڕێگە لە نرخی سفر دەگرێت.- Lineدێڕی 6
Calories describe the item, not one sale, so they belong in
items.کالۆری وەسفی خواردنەکە دەکات، نەک یەک فرۆشتن، بۆیە شوێنی لە
itemsـدایە.- Lineدێڕی 12-19
A bill lists many items and an item is on many bills: many-to-many, so a junction table with the quantity.
پسوولەیەک چەند خواردنێک لیست دەکات و خواردنێک لە چەند پسوولەیەکدایە: ، بۆیە لەگەڵ بڕەکە.
- Lineدێڕی 23-24
Two wrong rows: a reused bill number and an item that does not exist. Both are refused.
دوو هەڵە: ژمارەی پسوولەیەکی دووبارە و خواردنێک کە بوونی نییە. هەردووکیان ڕەت دەکرێنەوە.
The library now buys several copies of popular books, so a loan must say which copy went out. Students may also reserve a book that is out; any copy will do. Change the library's tables.
کتێبخانەکە ئێستا چەند دانەیەک لە کتێبە داواکراوەکان دەکڕێت، بۆیە هەر خواستنێک دەبێت بڵێت کام دانە دەرچووە. قوتابیان دەتوانن کتێبێکیش حیجز بکەن کە لە دەرەوەیە؛ هەر دانەیەک بێت باشە. کتێبخانەکە بگۆڕە.
Hintئاماژە
Can a copy be identified without knowing its book?
ئایا دانەیەک بەبێ زانینی کتێبەکەی دەناسرێتەوە؟
Show answerوەڵامەکە پیشان بدە
books (book_id PK, title)
copies (book_id FK -> books, copy_no)
PK = book_id + copy_no
loans (student_id FK -> students, book_id, copy_no, loan_date, return_date)
FK (book_id, copy_no) -> copies
PK = book_id + copy_no + loan_date
reservations (student_id FK -> students, book_id FK -> books, reserved_on)
PK = student_id + book_id + reserved_onExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2-3
'Copy 2' means nothing without its book: a copy is a weak entity, identified by
book_idplus its partial keycopy_no.«دانەی 2» بەبێ کتێبەکەی هیچ واتایەکی نییە: دانە قەوارەی لاوازە، بە
book_idلەگەڵcopy_noدەناسرێتەوە.- Lineدێڕی 4-6
A loan takes one physical copy, so it points to a copy.
خواستنێک یەک دانەی ڕاستەقینە دەبات، بۆیە ئاماژە بە دانەیەک دەکات.
- Lineدێڕی 7-8
A reservation is for the title, not for one copy: whichever copy comes back first goes to the student.
حیجز بۆ کتێبەکەیە، نەک بۆ یەک دانە: هەر دانەیەک یەکەم جار بگەڕێتەوە دەدرێتە قوتابییەکە.
Tested in SQLite: a loan of copy 3, which does not exist, is refused with FOREIGN KEY constraint failed.
لە SQLite تاقی کرایەوە: خواستنی دانەی 3، کە بوونی نییە، بە FOREIGN KEY constraint failed ڕەت دەکرێتەوە.
Exercisesڕاهێنانەکان
More exercises: indexes and a real projectڕاهێنانی زیاتر: پێڕستەکان و پڕۆژەیەکی ڕاستەقینە
The librarian lists every loan by date: SELECT * FROM loans ORDER BY loan_date;. Predict what SQLite does before and after CREATE INDEX idx_loans_date ON loans (loan_date);, then check with EXPLAIN QUERY PLAN.
کتێبدارەکە هەموو خواستنەکان بەپێی ڕێکەوت لیست دەکات: SELECT * FROM loans ORDER BY loan_date;. پێشبینی بکە SQLite پێش و دوای CREATE INDEX idx_loans_date ON loans (loan_date); چی دەکات، پاشان بە EXPLAIN QUERY PLAN بیپشکنە.
Show answerوەڵامەکە پیشان بدە
EXPLAIN QUERY PLAN SELECT * FROM loans ORDER BY loan_date;
CREATE INDEX idx_loans_date ON loans (loan_date);
EXPLAIN QUERY PLAN SELECT * FROM loans ORDER BY loan_date;QUERY PLAN |--SCAN loans `--USE TEMP B-TREE FOR ORDER BY QUERY PLAN `--SCAN loans USING INDEX idx_loans_date
Before: SQLite reads the whole table and then sorts it in a temporary B-tree. After: it walks the index, which is already in date order, so no sort is needed. This is not always the faster way: on a huge table on disk, reading every row through a secondary index costs one jump per row, so a DBMS may prefer to read the table straight through and sort it. The index clearly wins when only the first rows are wanted, as in ORDER BY loan_date DESC LIMIT 10.
پێش: SQLite هەموو دەخوێنێتەوە و پاشان لە B-treeـێکی کاتیدا ڕیزی دەکات. دوای: بە دەڕوات کە پێشتر بەپێی ڕێکەوت ڕیز کراوە، بۆیە پێویست بە ڕیزکردن نییە. ئەمە هەمیشە ڕێگا خێراترەکە نییە: لە زۆر گەورەدا لەسەر دیسک، خوێندنەوەی هەموو لە ڕێگەی بۆ هەر بازێکی دەوێت، بۆیە لەوانەیە پێی باشتر بێت ڕاستەوخۆ بخوێنێتەوە و ڕیزی بکات. بە ڕوونی دەباتەوە کاتێک تەنها یەکەم پێویستن، وەک لە ORDER BY loan_date DESC LIMIT 10.
Choose a small organisation you know: a car showroom in Duhok, a photo studio, a clinic in Halabja, a charity fund or a theatre group. Interview someone who works there if you can. Write its four analysis products: input documents, routine reports, screens for routine jobs and assumptions. Do not design any tables yet.
دامەزراوەیەکی بچووک هەڵبژێرە کە دەیناسیت: پێشانگایەکی ئۆتۆمبێل لە دهۆک، ستۆدیۆیەکی وێنەگرتن، کلینیکێک لە هەڵەبجە، سندووقێکی خێرخوازی یان گرووپێکی شانۆ. ئەگەر دەتوانیت، چاوپێکەوتن لەگەڵ کەسێک بکە کە لەوێ کار دەکات. چوار بەرهەمەکەی بنووسە: فۆرمەکان، ڕاپۆرتە ئاساییەکان، شاشەکانی کاری ڕۆژانە و گریمانەکان. هێشتا هیچ دیزاین مەکە.
Show answerوەڵامەکە پیشان بدە
A sample answer for a photo studio:
وەڵامێکی نموونەیی بۆ ستۆدیۆیەکی وێنەگرتن:
- Input documents: a booking form (name, phone, date, package) and the contract.
- Reports: this week's sessions for each photographer; unpaid balances; the most popular packages each month.
- Screens: new booking, record a payment, mark the photos as delivered.
- Assumptions: each booking has one main photographer; a deposit is paid when booking; photos are delivered within 14 days; each package has a fixed price in IQD.
- فۆرمەکان: فۆرمی حیجزکردن (ناو، ژمارەی مۆبایل، ڕێکەوت، پاکێج) و گرێبەستەکە.
- ڕاپۆرتەکان: دانیشتنەکانی ئەم هەفتەیە بۆ هەر وێنەگرێک؛ ئەو پارانەی هێشتا نەدراون؛ باوترین پاکێجەکانی هەر مانگێک.
- شاشەکان: حیجزی نوێ، تۆمارکردنی پارەدانێک، نیشانکردنی وێنەکان وەک گەیەنراو.
- گریمانەکان: هەر حیجزێک یەک وێنەگری سەرەکیی هەیە؛ بەشێک لە پارەکە لە کاتی حیجزکردندا دەدرێت؛ وێنەکان پێش تێپەڕبوونی ١٤ ڕۆژ دەگەیەنرێن؛ هەر پاکێجێک نرخێکی جێگیری بە دینار هەیە.
Summary and reviewپوختە و پێداچوونەوە
- The database development life cycle has eight steps: planning, analysis, conceptual design, logical design, physical design, implementation and data loading, testing, deployment and maintenance.
- Planning sets the goal, the scope and the standards. Analysis (requirement gathering) produces the requirement specifications.
- Design has three stages: conceptual (E-R diagram), logical (attributes, keys, normalization, constraints) and physical (tables, data types and indexes for one DBMS).
- Entity → table; one-to-many → foreign key on the 'many' side; many-to-many → junction table; multi-valued attribute → its own table.
- Indexes make searches fast but cost storage and slow down writes.
- Build the tables, clean and load the data, test with strange values, deploy to production, then maintain it. New needs start the cycle again.
- هەشت هەنگاوی هەیە: ، ، ، ، ، و ، ، و .
- ئامانج، و ستانداردەکان دادەنێت. (کۆکردنەوەی ) بەرهەم دەهێنێت.
- دیزاین سێ قۆناغی هەیە: چەمکی ()، لۆجیکی (، ، ، ) و فیزیکی (، و بۆ یەک ).
- ← ؛ ← لە لایەنی «زۆر»؛ ← ؛ ← جیا.
- گەڕان خێرا دەکەن بەڵام شوێن دەگرن و نووسین هێواش دەکەن.
- دروست بکە، پاک بکەرەوە و باری بکە، بە بەهای سەیر تاقی بکەرەوە، بیخەرە ناو ، پاشان چاکی ڕابگرە. پێویستیی نوێ سووڕەکە دووبارە دەست پێدەکاتەوە.
How many steps are in the database development life cycle?سووڕی ژیانی بنکەدراوە چەند هەنگاوی هەیە؟
Eight, from Planning through to Deployment and Maintenance.
هەشت، لە تا و .
What is another name for the Analysis step?ناوێکی تری هەنگاوی شیکردنەوەی پێداویستییەکان چییە؟
Requirement gathering. Its output is the requirement specifications.
کۆکردنەوەی . بەرهەمەکەی .
Which three stages make up the design phase?قۆناغی دیزاین لە کام سێ قۆناغ پێکدێت؟
Conceptual design, logical design and physical design.
، و .
At which step is the database linked to a real DBMS?لە کام هەنگاودا بنکەدراوەکە بە سیستەمێکی بەڕێوەبردنی بنکەدراوەی ڕاستەقینەوە دەبەسترێتەوە؟
Physical design: converting entities to tables and assigning data types.
: گۆڕینی بۆ و دانانی .
Why is it important to agree the scope during planning?بۆچی گرنگە لە کاتی پلاندانانی بنکەدراوەدا لەسەر مەودای پڕۆژە ڕێک بکەوین؟
Scope says what is inside the project and what is not. Agreeing it early stops the job growing without end.
دەڵێت چی لە ناو پڕۆژەکەدایە و چی نییە. ڕێککەوتن لەسەری لە سەرەتاوە ڕێگری دەکات لەوەی کارەکە بێکۆتایی گەورە ببێت.
Why not put an index on every column?بۆچی پێڕست لەسەر هەموو ستوونێک دانانێین؟
Every index uses extra storage and must be updated by every insert, update and delete, so writes become slower.
هەر شوێنی زیادە دەگرێت و دەبێت لە هەموو زیادکردن، گۆڕین و سڕینەوەیەکدا نوێ بکرێتەوە، بۆیە نووسین هێواشتر دەبێت.
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
Database Security: Threats and Countermeasuresئاسایشی بنکەدراوە: هەڕەشەکان و ڕێوشوێنەکانی بەرگری
Related lecturesوانە پەیوەندیدارەکان
- Creating a database with phpMyAdminدروستکردنی بنکەدراوە بە phpMyAdmin
- Inserting and selecting data with PHPزیادکردن و هەڵبژاردنی زانیاری بە PHP
- Databases and SQL basicsبنکەدراوەکان و بنەماکانی SQL
- Database Security: Threats and Countermeasuresئاسایشی بنکەدراوە: هەڕەشەکان و ڕێوشوێنەکانی بەرگری
- Backup and Recoveryباکئەپ و گەڕاندنەوەی دراوە
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
- Microsoft Support: Database design basics
- Silberschatz, Korth and Sudarshan: Database System Concepts, 7th ed., slides for chapter 6 (E-R model and reduction to relation schemas)
- MySQL 8.4 Reference Manual: How MySQL Uses Indexes
- MySQL 8.4 Reference Manual: Optimization and Indexes
- MySQL 8.4 Reference Manual: FOREIGN KEY Constraints
- Microsoft Learn: Primary and foreign key constraints (SQL Server)
- SQLite: EXPLAIN QUERY PLAN
- MySQL 8.4 Reference Manual: Clustered and Secondary Indexes
- PostgreSQL Documentation: Index Types
- MySQL 8.4 Reference Manual: The MEMORY Storage Engine
- Oracle Database Data Warehousing Guide: Data Warehousing Optimizations and Techniques (bitmap indexes)
- MySQL 8.4 Reference Manual: Server Character Set and Collation
- SIX: ISO 4217 currency codes (maintenance agency)
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.