Labs ICT
⭐ Pro Login

The Relational Model

Tables, rows, columns, and the foundation of modern databases.

Tables, Rows, and Columns

The relational model organizes data into tables (also called relations). Each table represents an entity β€” students, courses, orders, products. A table has columns (attributes) that define what data is stored, and rows (tuples) that represent individual records.

Key Terminology


  Table = Relation (e.g., Students)
  Row   = Tuple   (e.g., one student's data)
  Column = Attribute (e.g., Name, Age, Email)

  Students Table
  β”Œβ”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚ ID β”‚ Name    β”‚ Age β”‚ Email                β”‚
  β”œβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  β”‚ 1  β”‚ Alice   β”‚ 25  β”‚ alice@example.com    β”‚
  β”‚ 2  β”‚ Bob     β”‚ 22  β”‚ bob@example.com      β”‚
  β”‚ 3  β”‚ Charlie β”‚ 23  β”‚ charlie@example.com  β”‚
  β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    ↑     ↑       ↑           ↑
  Primary Key  Column definitions

Keys

Keys are fundamental to the relational model. They uniquely identify rows and establish relationships between tables.

  • Primary Key β€” A column (or set of columns) that uniquely identifies each row. No two rows can have the same primary key value. Cannot be NULL.
  • Foreign Key β€” A column in one table that references the primary key of another table. This is how relationships between tables are established.
  • Composite Key β€” A primary key made up of two or more columns together.
  • Candidate Key β€” Any column that could potentially be a primary key (unique and non-null).

  Students                    Enrollments
  β”Œβ”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”Œβ”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”
  β”‚ ID β”‚ Name    β”‚           β”‚SID β”‚CourseID β”‚Grade β”‚
  β”œβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€           β”œβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€
  β”‚ 1  β”‚ Alice   │◄──────────│ 1  β”‚ 101     β”‚ A    β”‚
  β”‚ 2  β”‚ Bob     │◄──┐       β”‚ 2  β”‚ 101     β”‚ B    β”‚
  β”‚ 3  β”‚ Charlie β”‚   β”‚       β”‚ 1  β”‚ 103     β”‚ A    β”‚
  β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚       β”‚ 3  β”‚ 103     β”‚ B+   β”‚
                     └───────│ 3  β”‚ 102     β”‚ A-   β”‚
                             β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜
  ID = Primary Key         SID = Foreign Key β†’ Students.ID
                           CourseID = Foreign Key β†’ Courses.ID

Relationships

  • One-to-One (1:1) β€” Each row in Table A relates to exactly one row in Table B. (e.g., Person β†’ Passport)
  • One-to-Many (1:N) β€” Each row in Table A relates to many rows in Table B. (e.g., Department β†’ Employees)
  • Many-to-Many (M:N) β€” Rows in Table A relate to many rows in Table B, and vice versa. Implemented using a junction table. (e.g., Students ↔ Courses)

πŸ§ͺ Quick Quiz

What is a composite primary key?