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)