Database Schema

 

A database schema is a blueprint that defines the structure of the database. It includes tables, columns, data types, relationships, and constraints. The schema is a crucial part of database design and provides a clear plan for how data will be stored, organized, and accessed.

 

Keys

 

Keys are attributes or sets of attributes that help in uniquely identifying rows within a table. There are several types of keys, each serving a specific purpose:

  1. Primary Key:

    • Uniquely identifies each row in a table.
    • A table can have only one primary key.
    • Example: STUDENT_ID in the STUDENT table.
  2. Foreign Key:

    • Establishes a relationship between two tables.
    • References the primary key of another table.
    • Example: STUDENT_ID in the ENROLLMENT table referencing STUDENT_ID in the STUDENT table.
  3. Candidate Key:

    • A minimal set of attributes that can uniquely identify a tuple.
    • There can be multiple candidate keys in a table.
    • Example: STUDENT_ID and ROLL_NO can be candidate keys if both uniquely identify students.
  4. Alternate Key:

    • A candidate key that is not chosen as the primary key.
    • Example: If STUDENT_ID is the primary key, ROLL_NO can be an alternate key.
  5. Composite Key:

    • A primary key that consists of more than one attribute.
    • Example: (STUDENT_ID, COURSE_ID) in the ENROLLMENT table.
  6. Super Key:

    • A set of one or more attributes that, taken collectively, uniquely identify a tuple.
    • Example: {STUDENT_ID, NAME} is a super key in the STUDENT table, but not necessarily a candidate key if NAME is not unique.