© 2026 schoolict.net (Ruwan Mangala Suraweera)
8.2 Relational Database Model and Constraintsසම්බන්ධතා දත්ත සමුදාය ආකෘතිය සහ සීමා කිරීම්
Grade 13 A/L ICT · Lesson 813 ශ්රේණිය A/L ICT · පාඩම 8
In this videoමේ වීඩියෝවේ
- A relation is a table of tuples and attributes.සම්බන්ධතාව tuples සහ උපලක්ෂණ වගුවකි.
- Degree = columns; cardinality = rows.මානය = තීරු; ගණනීයතාව = පේළි.
- Primary key = unique + not null.ප්රාථමික යතුර = අනන්ය + null නොවේ.
- Foreign keys keep links between tables valid.විදේශීය යතුරු වගු සබැඳි වලංගු තබයි.
- CHECK and NOT NULL stop invalid values.CHECK සහ NOT NULL වැරදි අගයන් වළක්වයි.
Notesසටහන්
Syllabus 8.2. The relational model stores data in relations (tables). A relation has attributes (columns) and tuples (rows), and tables are joined by relationships. Constraints – NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY and CHECK – stop bad data from entering.විෂය නිර්දේශය 8.2. සම්බන්ධතා ආකෘතිය දත්ත සම්බන්ධතා (වගු) තුළ ගබඩා කරයි. සම්බන්ධතාවකට උපලක්ෂණ (තීරු) සහ tuples (පේළි) ඇති අතර වගු සම්බන්ධතා මගින් යා වේ. සීමා කිරීම් – NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY සහ CHECK – වැරදි දත්ත ඇතුළු වීම වළක්වයි.
1. Relations, attributes and tuples1. සම්බන්ධතා, උපලක්ෂණ සහ tuples
- Relation / table – a named set of rows with the same columns.සම්බන්ධතාව / වගුව – එකම තීරු ඇති පේළිවල නම් කළ කට්ටලයකි.
- Attribute / column – one property, e.g. Name; it has a domain (allowed values).උපලක්ෂණය / තීරුව – එක් ගුණයක්, උදා: Name; එයට වසමක් (අවසර අගයන්) ඇත.
- Tuple / row – one record, e.g. (S001, Nimal, C12A).Tuple / පේළිය – එක් වාර්තාවක්, උදා: (S001, Nimal, C12A).
- Degree = number of columns; cardinality = number of rows.මානය = තීරු ගණන; ගණනීයතාව = පේළි ගණන.
- Relationship – a link between tables through matching key values.සම්බන්ධතාව – ගැළපෙන යතුරු අගයන් හරහා වගු අතර සබැඳිය.
2. Types of constraints2. සීමා කිරීම් වර්ග
📝 Table definitions with constraints (SQL)සීමා කිරීම් සහිත වගු නිර්වචන (SQL)
CREATE TABLE Class ( ClassID CHAR(4) PRIMARY KEY, ClassName VARCHAR(10) NOT NULL UNIQUE, Teacher VARCHAR(30) NOT NULL ); CREATE TABLE Student ( StudentID CHAR(4) PRIMARY KEY, Name VARCHAR(30) NOT NULL, ClassID CHAR(4) REFERENCES Class(ClassID) ); CREATE TABLE Marks ( StudentID CHAR(4) REFERENCES Student(StudentID), SubjectCode CHAR(4), Mark INTEGER CHECK (Mark BETWEEN 0 AND 100), PRIMARY KEY (StudentID, SubjectCode) );
| Constraintසීමා කිරීම | Ruleනීතිය | Rejected exampleප්රතික්ෂේප වූ උදාහරණය |
|---|---|---|
| NOT NULLNOT NULL | A value must be givenඅගයක් ලබා දිය යුතුය | Class with no TeacherTeacher නැති Class |
| UNIQUEUNIQUE | No two rows share the valueපේළි දෙකකට එකම අගය නැත | a second class named 12A12A නමින් දෙවන පන්තියක් |
| PRIMARY KEYPRIMARY KEY | Unique and not null; identifies a rowඅනන්ය සහ null නොවේ; පේළිය හඳුනාගනී | a second S001දෙවන S001 |
| FOREIGN KEYFOREIGN KEY | Value must exist in the parent tableඅගය මව් වගුවේ තිබිය යුතුය | ClassID C13Z (no such class)ClassID C13Z (එවැනි පන්තියක් නැත) |
| CHECKCHECK | Value must pass a conditionඅගය කොන්දේසියක් සපුරාලිය යුතුය | Mark 105ලකුණ 105 |
We ran all five in sqlite3 with foreign keys on. All 5 were rejected: S001 again (primary key), class C13Z (foreign key), mark 105 (CHECK 0–100), a NULL teacher (NOT NULL) and a second 12A (UNIQUE).sqlite3 තුළ foreign keys සක්රිය කර පහම ධාවනය කළෙමු. 5 ම ප්රතික්ෂේප විය: නැවත S001 (ප්රාථමික යතුර), C13Z (විදේශීය යතුර), ලකුණ 105 (CHECK), NULL ගුරුවරයා (NOT NULL) සහ දෙවන 12A (UNIQUE).
Key Wordsප්රධාන පද
Sample Q&Aආදර්ශ ප්රශ්න සහ පිළිතුරු
1What is a tuple?Tuple යනු?
2Degree and cardinality of the Student table shown?පෙන්වූ Student වගුවේ මානය සහ ගණනීයතාව?
3What does a foreign key constraint prevent?විදේශීය යතුරු සීමාව වළක්වන්නේ?
4How is PRIMARY KEY different from UNIQUE?PRIMARY KEY සහ UNIQUE වෙනස?
5Write a CHECK for marks.ලකුණු සඳහා CHECK.
6What is a domain?වසම යනු?
MCQබහුවරණ ප්රශ්න
Choose the correct answer for each question.සෑම ප්රශ්නයකටම නිවැරදි පිළිතුර තෝරන්න.
1A row of a relation is called aපේළිය
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Tuple.Tuple.
2A column of a relation is called anතීරුව
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
Attribute.උපලක්ෂණය.
3The number of columns in a relation is itsතීරු ගණන
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Degree.මානය.
4A rule that a value must exist in the parent table is aමව් වගුව
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
FK.FK.
5Inserting mark 105 is rejected by105
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
CHECK.CHECK.
6Inserting a second S001 breaks theS001
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
Duplicate key.අනුපිටපත් යතුර.
7A constraint that is UNIQUE and NOT NULL together isUNIQUE + NOT NULL
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Primary key.ප්රාථමික යතුර.
8Of the five bad inserts tested in sqlite3, how many were rejected?ප්රතික්ෂේප
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E
All rejected.සියල්ල.
9Which term means: “A table of rows with the same columns”?“එකම තීරු ඇති පේළි වගුවක්” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Relation – A table of rows with the same columns.සම්බන්ධතාව – එකම තීරු ඇති පේළි වගුවක්.
10Which term means: “A column that holds one property”?“එක් ගුණයක් රඳවන තීරුවක්” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
Attribute – A column that holds one property.උපලක්ෂණය – එක් ගුණයක් රඳවන තීරුවක්.
11Which term means: “A single row or record of a relation”?“සම්බන්ධතාවක එක් පේළියක් හෝ වාර්තාවක්” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
Tuple – A single row or record of a relation.Tuple – සම්බන්ධතාවක එක් පේළියක් හෝ වාර්තාවක්.
12Which term means: “The set of allowed values for an attribute”?“උපලක්ෂණයකට අවසර අගයන් කට්ටලය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E
Domain – The set of allowed values for an attribute.වසම – උපලක්ෂණයකට අවසර අගයන් කට්ටලය.
13Which term means: “The number of attributes in a relation”?“සම්බන්ධතාවක උපලක්ෂණ ගණන” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E
Degree – The number of attributes in a relation.මානය – සම්බන්ධතාවක උපලක්ෂණ ගණන.
14Which term means: “The number of tuples in a relation”?“සම්බන්ධතාවක tuples ගණන” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
Cardinality – The number of tuples in a relation.ගණනීයතාව – සම්බන්ධතාවක tuples ගණන.
15Which term means: “A link between tables using key values”?“යතුරු අගයන් භාවිතයෙන් වගු අතර සබැඳිය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
Relationship – A link between tables using key values.සම්බන්ධතාව (සබැඳිය) – යතුරු අගයන් භාවිතයෙන් වගු අතර සබැඳිය.
16Which term means: “Rule that a column must always have a value”?“තීරුවකට සැමවිටම අගයක් තිබිය යුතු නීතිය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
NOT NULL constraint – Rule that a column must always have a value.NOT NULL සීමාව – තීරුවකට සැමවිටම අගයක් තිබිය යුතු නීතිය.
17Which term means: “Rule that no two rows share a column value”?“පේළි දෙකකට එකම තීරු අගය නොතිබිය යුතු නීතිය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
UNIQUE constraint – Rule that no two rows share a column value.UNIQUE සීමාව – පේළි දෙකකට එකම තීරු අගය නොතිබිය යුතු නීතිය.
18Which term means: “Unique, not null column that identifies each row”?“සෑම පේළියක්ම හඳුනාගන්නා අනන්ය, null නොවන තීරුව” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Primary key constraint – Unique, not null column that identifies each row.ප්රාථමික යතුරු සීමාව – සෑම පේළියක්ම හඳුනාගන්නා අනන්ය, null නොවන තීරුව.
19Which term means: “Rule that a value must exist in the referenced table”?“අගය යොමු කළ වගුවේ තිබිය යුතු නීතිය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Foreign key constraint – Rule that a value must exist in the referenced table.විදේශීය යතුරු සීමාව – අගය යොමු කළ වගුවේ තිබිය යුතු නීතිය.
20Which term means: “Rule that a value must satisfy a condition”?“අගය කොන්දේසියක් සපුරාලිය යුතු නීතිය” යන්නෙන් අදහස් වන පදය කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E
Check constraint – Rule that a value must satisfy a condition.CHECK සීමාව – අගය කොන්දේසියක් සපුරාලිය යුතු නීතිය.
MCQ answer keyMCQ පිළිතුරු
- A – Tuple.Tuple.
- B – Attribute.උපලක්ෂණය.
- A – Degree.මානය.
- C – FK.FK.
- B – CHECK.CHECK.
- D – Duplicate key.අනුපිටපත් යතුර.
- A – Primary key.ප්රාථමික යතුර.
- E – All rejected.සියල්ල.
- A – Relation – A table of rows with the same columns.සම්බන්ධතාව – එකම තීරු ඇති පේළි වගුවක්.
- B – Attribute – A column that holds one property.උපලක්ෂණය – එක් ගුණයක් රඳවන තීරුවක්.
- D – Tuple – A single row or record of a relation.Tuple – සම්බන්ධතාවක එක් පේළියක් හෝ වාර්තාවක්.
- E – Domain – The set of allowed values for an attribute.වසම – උපලක්ෂණයකට අවසර අගයන් කට්ටලය.
- E – Degree – The number of attributes in a relation.මානය – සම්බන්ධතාවක උපලක්ෂණ ගණන.
- B – Cardinality – The number of tuples in a relation.ගණනීයතාව – සම්බන්ධතාවක tuples ගණන.
- D – Relationship – A link between tables using key values.සම්බන්ධතාව (සබැඳිය) – යතුරු අගයන් භාවිතයෙන් වගු අතර සබැඳිය.
- C – NOT NULL constraint – Rule that a column must always have a value.NOT NULL සීමාව – තීරුවකට සැමවිටම අගයක් තිබිය යුතු නීතිය.
- D – UNIQUE constraint – Rule that no two rows share a column value.UNIQUE සීමාව – පේළි දෙකකට එකම තීරු අගය නොතිබිය යුතු නීතිය.
- C – Primary key constraint – Unique, not null column that identifies each row.ප්රාථමික යතුරු සීමාව – සෑම පේළියක්ම හඳුනාගන්නා අනන්ය, null නොවන තීරුව.
- C – Foreign key constraint – Rule that a value must exist in the referenced table.විදේශීය යතුරු සීමාව – අගය යොමු කළ වගුවේ තිබිය යුතු නීතිය.
- E – Check constraint – Rule that a value must satisfy a condition.CHECK සීමාව – අගය කොන්දේසියක් සපුරාලිය යුතු නීතිය.
Structured Questionsව්යුහගත ප්රශ්න
1Define relation, attribute and tuple using the Student table.Student වගුවෙන් අර්ථ දක්වන්න. (3 marksලකුණු 3)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
2State the degree and cardinality of a table with 3 columns and 5 rows.තීරු 3, පේළි 5. (2 marksලකුණු 2)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
3Explain five types of constraints with an example each.සීමා කිරීම් පහ. (5 marksලකුණු 5)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
4Write SQL to create Marks with a composite primary key and a CHECK.Marks සාදන SQL. (4 marksලකුණු 4)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
5Explain how a foreign key keeps referential integrity.referential integrity. (3 marksලකුණු 3)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
🎮 Game🎮 ක්රීඩා
Summary & Downloadsසාරාංශය සහ බාගත කිරීම්
Key pointsප්රධාන කරුණු
- A relation is a table of tuples and attributes.සම්බන්ධතාව tuples සහ උපලක්ෂණ වගුවකි.
- Degree = columns; cardinality = rows.මානය = තීරු; ගණනීයතාව = පේළි.
- Primary key = unique + not null.ප්රාථමික යතුර = අනන්ය + null නොවේ.
- Foreign keys keep links between tables valid.විදේශීය යතුරු වගු සබැඳි වලංගු තබයි.
- CHECK and NOT NULL stop invalid values.CHECK සහ NOT NULL වැරදි අගයන් වළක්වයි.
