Thursday, January 30, 2025
HomeComputer ScienceWhat is a relation schema in DBMS?

What is a relation schema in DBMS?

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)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:

See also  What Does "opt" Mean (as in the "opt" Directory)? - Linux

Student(StudentID,Name,Age,Major)Student( Student_ID, Name, Age, Major )

  • Relation Name: Student
  • Attributes: Student_ID, Name, Age, Major
  • Domains:
    • Student_ID → Integer (Unique Identifier)
    • Name → String
    • Age → Integer
    • Major → 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 → Integer
  • Name → Varchar(50)
  • Age → Integer
  • Major → Varchar(30)

(b) Constraints in Relation Schema

  1. Primary Key → Uniquely identifies each row (e.g., Student_ID)
  2. Foreign Key → Establishes a relationship with another table
  3. Not Null → Ensures a field cannot have NULL values
  4. Unique → Ensures values in a column are unique
  5. 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
See also  What Are The Applications Of Machine Learning?

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

See also  Introduction of Classful IP Addressing

 

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x