Relation Schema and Relation Instance
A relation schema is the fixed definition of a relation; a relation instance is the set of tuples in it right now. A relational database schema is the collection of all relation schemas plus their constraints.
-
DBMS Fundamentals
- Data, Information and Databases
- What a DBMS Is and Why It Exists
- File System versus DBMS
- Advantages and Limitations of a DBMS
- Database Users and the Role of the DBA
- Three Level Architecture and Data Abstraction
- Logical and Physical Data Independence
- Schema, Instance and Metadata
- Database Applications and the Database System Environment
- Database Architecture
- Data Models
-
ER Model
- Entities, Entity Sets and Entity Types
- Types of Attributes in the ER Model
- Keys in the ER Model
- Relationships, Relationship Sets and Degree
- Cardinality and Participation Constraints
- Strong and Weak Entities
- Drawing and Reading ER Diagrams
- Extended ER: Generalisation, Specialisation and Aggregation
- Converting an ER Diagram into Relational Tables
- ER Design Projects
- Relational Model
- Relational Algebra
- Functional Dependencies
-
Normalisation
- Why Normalisation Exists: Anomalies and Redundancy
- First Normal Form
- Second Normal Form and Partial Dependency
- Third Normal Form and Transitive Dependency
- BCNF and BCNF Decomposition
- 4NF, 5NF, Multivalued and Join Dependencies
- Lossless Decomposition and Dependency Preservation
- Complete Worked Normalisation: Unnormalised to BCNF
- Denormalisation and When to Use It
Concept
Phase 1 introduced schema and instance for the whole database. The same distinction applies to one relation, and the relational model gives it a precise notation.
| Relation schema | Relation instance | |
|---|---|---|
| What it is | Name plus the list of attributes and their domains | The set of tuples present at one moment |
| Notation | STUDENT ( roll_no, name, marks ) | The actual rows |
| Also called | Intension | Extension, state |
| Changes | Rarely, by a definition statement | Constantly, by data statements |
| Count | One per relation | One at any moment, different at the next |
RELATION SCHEMA (fixed)
STUDENT ( roll_no : integer
, name : string
, marks : integer 0..100 )
RELATION INSTANCE at 10:00 INSTANCE at 10:05
21 Meera 87 21 Meera 87
22 Ravi 91 22 Ravi 93 <- updated
23 Anitha 78 <- inserted
Same schema. Different instance. Neither instance is
more correct than the other; both satisfy the schema.Relational database schema
A relational database schema is the set of all relation schemas in the database, together with every integrity constraint. Written as a set:
COLLEGE = {
DEPARTMENT ( dept_code, dept_name, building )
, STUDENT ( roll_no, name, dob, dept_code )
, COURSE ( course_code, title, credits, dept_code )
, ENROLMENT ( roll_no, course_code, semester, marks )
}
plus constraints:
STUDENT.dept_code references DEPARTMENT.dept_code
COURSE.dept_code references DEPARTMENT.dept_code
ENROLMENT.roll_no references STUDENT.roll_no
ENROLMENT.course_code references COURSE.course_code
marks between 0 and 100Valid and invalid instances
An instance is valid only if it satisfies every constraint in the schema. This is the definition that makes constraints meaningful: the schema does not merely describe the data, it restricts which instances are allowed to exist.
SCHEMA
STUDENT ( roll_no PK, name NOT NULL, marks 0..100
, dept_code -> DEPARTMENT )
INVALID INSTANCE, four separate violations
21 Meera 87 CS ok
21 Ravi 91 CS <- duplicate primary key
23 (null) 78 CS <- name is null
24 Anitha 150 CS <- marks outside the domain
25 Kumar 65 ZZ <- no such department
A DBMS rejects each of these at the moment it is attempted.
Without the constraints, all four would be stored happily.Notation used through the rest of this path
| Notation | Means |
|---|---|
R ( A, B, C ) | Relation R with attributes A, B and C |
| Underlined attribute | Primary key |
| Arrow to another relation | Foreign key |
r(R) | An instance of relation schema R |
t[A] | The value of attribute A in tuple t |
|r| | Cardinality — the number of tuples |
The notation t[A] matters from Phase 7 onward, because functional dependencies are defined in exactly those terms: if two tuples agree on X they must agree on Y.
Common mistakes
- Saying the schema changes when data is inserted. That is a new instance.
- Forgetting constraints are part of the schema. A database schema is relation schemas plus constraints, and marks are given for saying so.
- Thinking any set of tuples is an instance. Only sets satisfying every constraint are valid instances.
- Confusing relation schema with relational database schema. One relation versus all of them.
Exam and interview questions
- Differentiate relation schema and relation instance with an example.
- What is a relational database schema, and what does it include besides relations?
- Define a valid instance.
- Given a schema and four rows, identify each constraint violation.
- What do intension and extension mean?
Practice
- Write the relation schema and one valid instance for a library BOOK relation.
- Write an invalid instance of it with three different violations and name each.
- Write the full relational database schema for the hospital design from Phase 4b, including constraints.
Conclusion
The relation schema is the fixed definition, the instance is the current set of tuples, and the database schema is every relation schema plus every constraint. An instance is valid only when it satisfies all of them — which is what makes a constraint more than documentation.