Relation Schema in DBMS
In Database Management Systems (DBMS), a relation schema defines the structure of a relation (table) in a relational database. It specifies:
- Relation name (table name)
- Attributes (columns/fields)
- Domain (data types) of attributes
- Constraints (like primary keys, foreign keys, etc.)
1️⃣ Relation Schema Definition
A relation schema is typically represented as:
R(A1,A2,A3,…,An)R(A_1, A_2, A_3, …, A_n)R(A1,A2,A3,…,An)Where:
- R → Name of the relation (table)
- A₁, A₂, A₃, …, Aₙ → Attributes (columns of the table)
Each attribute has a domain, which defines the type of values it can store.
2️⃣ Example of Relation Schema
Consider a Student table:
Student(StudentID,Name,Age,Major)Student( Student_ID, Name, Age, Major )Student(StudentID,Name,Age,Major)
- Relation Name:
Student
- Attributes:
Student_ID
,Name
,Age
,Major
- Domains:
Student_ID
→ Integer (Unique Identifier)Name
→ StringAge
→ IntegerMajor
→ String
Corresponding Table (Relation)
Student_ID | Name | Age | Major |
---|---|---|---|
101 | Alice | 20 | CS |
102 | Bob | 21 | Math |
103 | Charlie | 22 | Physics |
3️⃣ Components of Relation Schema
(a) Attributes and Domains
Each attribute has a domain, which defines the type of values it can take.
Example:
Student_ID
→ IntegerName
→ Varchar(50)Age
→ IntegerMajor
→ Varchar(30)
(b) Constraints in Relation Schema
- Primary Key → Uniquely identifies each row (e.g.,
Student_ID
) - Foreign Key → Establishes a relationship with another table
- Not Null → Ensures a field cannot have NULL values
- Unique → Ensures values in a column are unique
- Check → Restricts values (e.g.,
Age > 18
)
Example with Constraints (SQL Representation):
CREATE TABLE Student (
Student_ID INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Age INT CHECK (Age > 18),
Major VARCHAR(30)
);
4️⃣ Difference Between Relation and Relation Schema
Aspect | Relation Schema | Relation (Table) |
---|---|---|
Definition | Structure/Blueprint of a table | Actual data stored in the table |
Contains | Table name, attributes, data types, constraints | Rows (tuples) with real data |
Example | Student(Student_ID, Name, Age, Major) |
Table with student records |
5️⃣ Key Takeaways
✔ Relation Schema → Defines table structure
✔ Attributes & Domains → Specify columns and their data types
✔ Constraints → Ensure data integrity (PK, FK, NOT NULL, etc.)
✔ Relation (Table) ≠ Relation Schema → One is the blueprint, the other is the actual data