Skip to main content

Relational Database Schemas and Keys

A relational database stores information in two-dimensional tables consisting of rows and columns.

  • Row: Represents a complete entity instance, also known as a tuple or record.
  • Column: Represents a field or attribute of the entity.

Relational Schemas

A schema outlines the structural definition of the table.

Example: For a Student table, the schema might look like this:

Student (StudentID, FirstName, LastName, CourseID)

Importance of Keys

Keys are fundamental to the relational model. They uniquely identify rows and create logical links across multiple tables.

1. Primary Key

A primary key uniquely identifies a specific row in a table. It must be unique and cannot be null.

2. Foreign Key

A foreign key is a column (or group of columns) in a table that provides a link to data in another table. It acts as a cross-reference between tables because it references the primary key of another table, establishing a relationship.

In the above schema, d_id inside EMPLOYEE is a Foreign Key referencing dept_id inside DEPARTMENT.