Relational Database Model and Constraints – Grade 13 A/L ICT Notes 8.2

© 2026 schoolict.net (Ruwan Mangala Suraweera)

8.2 Relational Database Model and Constraintsසම්බන්ධතා දත්ත සමුදාය ආකෘතිය සහ සීමා කිරීම්

Grade 13 A/L ICT · Lesson 813 ශ්‍රේණිය A/L ICT · පාඩම 8

Prints all tabs in the language you are reading. Use “Save as PDF” in the print window to keep a copy.ඔබ කියවන භාෂාවෙන් සියලු tabs මුද්‍රණය වේ. පිටපතක් තියාගන්න print window එකේ “Save as PDF” තෝරන්න.
🎬Video coming soon in this language. Switch language to watch the other video.මේ භාෂාවෙන් වීඩියෝව ඉක්මනින් එනවා. අනෙක් වීඩියෝව බලන්න භාෂාව මාරු කරන්න.

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 වැරදි අගයන් වළක්වයි.
RelationAttributeTupleDomainDegreeCardinalityRelationship

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

Parts of a relation (table)StudentIDNameClassIDS001NimalC12AS002KamalaC12AS003SunilC12B↑ attribute / column (field)highlighted row = tuple / recordPrimary key: StudentID · Foreign key: ClassID → Classdegree = 3 columns · cardinality = 3 rows
Parts of the Student relationStudent සම්බන්ධතාවේ කොටස්
  • 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 NULLA value must be givenඅගයක් ලබා දිය යුතුයClass with no TeacherTeacher නැති Class
UNIQUEUNIQUENo two rows share the valueපේළි දෙකකට එකම අගය නැතa second class named 12A12A නමින් දෙවන පන්තියක්
PRIMARY KEYPRIMARY KEYUnique and not null; identifies a rowඅනන්‍ය සහ null නොවේ; පේළිය හඳුනාගනීa second S001දෙවන S001
FOREIGN KEYFOREIGN KEYValue must exist in the parent tableඅගය මව් වගුවේ තිබිය යුතුයClassID C13Z (no such class)ClassID C13Z (එවැනි පන්තියක් නැත)
CHECKCHECKValue must pass a conditionඅගය කොන්දේසියක් සපුරාලිය යුතුයMark 105ලකුණ 105
🧮 Worked exampleවිසඳූ උදාහරණය Which of these inserts does the database reject, and why?දත්ත සමුදාය ප්‍රතික්ෂේප කරන ඇතුළත් කිරීම් සහ හේතු?
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).
💡 A primary key is UNIQUE + NOT NULL together; a table has only one primary key.ප්‍රාථමික යතුර = UNIQUE + NOT NULL; වගුවකට ඇත්තේ එක් ප්‍රාථමික යතුරක් පමණි.
🚀 Beyond the syllabus (2026 update)🚀 විෂය නිර්දේශයෙන් ඔබ්බට (2026 යාවත්කාලීනය) Not required for the exam – read for interest.විභාගයට අවශ්‍ය නැත – දැනුම සඳහා කියවන්න. Modern cloud databases in 2026 still enforce these same constraints, and AI coding assistants often suggest them when generating tables.2026 cloud දත්ත සමුදාය ද මෙම සීමා කිරීම් ම බලාත්මක කරයි; AI කේත සහායකයින් වගු සාදන විට ඒවා යෝජනා කරයි.

Key Wordsප්‍රධාන පද

Relationසම්බන්ධතාව
A table of rows with the same columns.එකම තීරු ඇති පේළි වගුවක්.
Attributeඋපලක්ෂණය
A column that holds one property.එක් ගුණයක් රඳවන තීරුවක්.
TupleTuple
A single row or record of a relation.සම්බන්ධතාවක එක් පේළියක් හෝ වාර්තාවක්.
Domainවසම
The set of allowed values for an attribute.උපලක්ෂණයකට අවසර අගයන් කට්ටලය.
Degreeමානය
The number of attributes in a relation.සම්බන්ධතාවක උපලක්ෂණ ගණන.
Cardinalityගණනීයතාව
The number of tuples in a relation.සම්බන්ධතාවක tuples ගණන.
Relationshipසම්බන්ධතාව (සබැඳිය)
A link between tables using key values.යතුරු අගයන් භාවිතයෙන් වගු අතර සබැඳිය.
NOT NULL constraintNOT NULL සීමාව
Rule that a column must always have a value.තීරුවකට සැමවිටම අගයක් තිබිය යුතු නීතිය.
UNIQUE constraintUNIQUE සීමාව
Rule that no two rows share a column value.පේළි දෙකකට එකම තීරු අගය නොතිබිය යුතු නීතිය.
Primary key constraintප්‍රාථමික යතුරු සීමාව
Unique, not null column that identifies each row.සෑම පේළියක්ම හඳුනාගන්නා අනන්‍ය, null නොවන තීරුව.
Foreign key constraintවිදේශීය යතුරු සීමාව
Rule that a value must exist in the referenced table.අගය යොමු කළ වගුවේ තිබිය යුතු නීතිය.
Check constraintCHECK සීමාව
Rule that a value must satisfy a condition.අගය කොන්දේසියක් සපුරාලිය යුතු නීතිය.

Sample Q&Aආදර්ශ ප්‍රශ්න සහ පිළිතුරු

1What is a tuple?Tuple යනු?

Answerපිළිතුර: One row (record) of a relation.සම්බන්ධතාවක එක් පේළියක්.

2Degree and cardinality of the Student table shown?පෙන්වූ Student වගුවේ මානය සහ ගණනීයතාව?

Answerපිළිතුර: Degree 3, cardinality 3.මානය 3, ගණනීයතාව 3.

3What does a foreign key constraint prevent?විදේශීය යතුරු සීමාව වළක්වන්නේ?

Answerපිළිතුර: Rows that refer to a parent record that does not exist.නොපවතින මව් වාර්තාවකට යොමු වන පේළි.

4How is PRIMARY KEY different from UNIQUE?PRIMARY KEY සහ UNIQUE වෙනස?

Answerපිළිතුර: Primary key is also NOT NULL and only one per table.ප්‍රාථමික යතුර NOT NULL ද වන අතර වගුවකට එකක් පමණි.

5Write a CHECK for marks.ලකුණු සඳහා CHECK.

Answerපිළිතුර: CHECK (Mark BETWEEN 0 AND 100).CHECK (Mark BETWEEN 0 AND 100).

6What is a domain?වසම යනු?

Answerපිළිතුර: The set of allowed values of an attribute, e.g. 0–100 for Mark.උපලක්ෂණයක අවසර අගයන්; උදා: 0–100.

MCQබහුවරණ ප්‍රශ්න

Choose the correct answer for each question.සෑම ප්‍රශ්නයකටම නිවැරදි පිළිතුර තෝරන්න.

Scoreලකුණු: 0 / 20

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 පිළිතුරු

  1. A – Tuple.Tuple.
  2. B – Attribute.උපලක්ෂණය.
  3. A – Degree.මානය.
  4. C – FK.FK.
  5. B – CHECK.CHECK.
  6. D – Duplicate key.අනුපිටපත් යතුර.
  7. A – Primary key.ප්‍රාථමික යතුර.
  8. E – All rejected.සියල්ල.
  9. A – Relation – A table of rows with the same columns.සම්බන්ධතාව – එකම තීරු ඇති පේළි වගුවක්.
  10. B – Attribute – A column that holds one property.උපලක්ෂණය – එක් ගුණයක් රඳවන තීරුවක්.
  11. D – Tuple – A single row or record of a relation.Tuple – සම්බන්ධතාවක එක් පේළියක් හෝ වාර්තාවක්.
  12. E – Domain – The set of allowed values for an attribute.වසම – උපලක්ෂණයකට අවසර අගයන් කට්ටලය.
  13. E – Degree – The number of attributes in a relation.මානය – සම්බන්ධතාවක උපලක්ෂණ ගණන.
  14. B – Cardinality – The number of tuples in a relation.ගණනීයතාව – සම්බන්ධතාවක tuples ගණන.
  15. D – Relationship – A link between tables using key values.සම්බන්ධතාව (සබැඳිය) – යතුරු අගයන් භාවිතයෙන් වගු අතර සබැඳිය.
  16. C – NOT NULL constraint – Rule that a column must always have a value.NOT NULL සීමාව – තීරුවකට සැමවිටම අගයක් තිබිය යුතු නීතිය.
  17. D – UNIQUE constraint – Rule that no two rows share a column value.UNIQUE සීමාව – පේළි දෙකකට එකම තීරු අගය නොතිබිය යුතු නීතිය.
  18. C – Primary key constraint – Unique, not null column that identifies each row.ප්‍රාථමික යතුරු සීමාව – සෑම පේළියක්ම හඳුනාගන්නා අනන්‍ය, null නොවන තීරුව.
  19. C – Foreign key constraint – Rule that a value must exist in the referenced table.විදේශීය යතුරු සීමාව – අගය යොමු කළ වගුවේ තිබිය යුතු නීතිය.
  20. 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ආදර්ශ පිළිතුර පෙන්වන්න
Relation table; attribute column; tuple row.වගුව; තීරුව; පේළිය.

2State the degree and cardinality of a table with 3 columns and 5 rows.තීරු 3, පේළි 5. (2 marksලකුණු 2)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
Degree 3; cardinality 5.මානය 3; ගණනීයතාව 5.

3Explain five types of constraints with an example each.සීමා කිරීම් පහ. (5 marksලකුණු 5)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
NOT NULL; UNIQUE; PRIMARY KEY; FOREIGN KEY; CHECK.NOT NULL; UNIQUE; PK; FK; CHECK.

4Write SQL to create Marks with a composite primary key and a CHECK.Marks සාදන SQL. (4 marksලකුණු 4)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
CREATE TABLE Marks; StudentID REFERENCES Student; CHECK Mark 0–100; PRIMARY KEY (StudentID, SubjectCode).CREATE TABLE; REFERENCES; CHECK; PRIMARY KEY.

5Explain how a foreign key keeps referential integrity.referential integrity. (3 marksලකුණු 3)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
FK value must match parent PK; rejects orphans; e.g. C13Z rejected.මව් PK ගැළපිය යුතුය; අනාථ පේළි නැත.

🎮 Game🎮 ක්‍රීඩා

Pick a game. Each one uses words from this lesson.ක්‍රීඩාවක් තෝරන්න. හැම එකක්ම මේ පාඩමේ වචන පාවිච්චි කරනවා.

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 වැරදි අගයන් වළක්වයි.

Downloadsබාගත කිරීම්

Full Lesson 8 PDFසම්පූර්ණ පාඩම 8 PDF: English · සිංහල

Next noteඊළඟ සටහන 8.3 →

© 2026 schoolict.net (Ruwan Mangala Suraweera). All rights reserved.සියලු හිමිකම් ඇවිරිණි.