ITEC 3200 Database Systems Review

Introduction to Database Systems & The Relational Model

  • Data Hierarchy

    • Bit: Binary digit (00 or 11).
    • Byte: Storage for a single character (usually 88 bits).
    • Field / Column / Attribute: A single data item or characteristic.
    • Record / Row / Tuple: A collection of related fields representing one instance of an entity.
    • Table / Relation: A two-dimensional set of related records.
    • Database (DBMS): Software used to store and manage a related set of tables.
  • DBMS Core Concepts

    • Primary Functions: Organize, store, retrieve, search, and enforce security over large volumes of data.
    • Core Components: Real-world Entities (nouns/objects), Attributes (properties), and Relationships (associations).
    • Database Administrator (DBA): Responsible for decisions, management, and security configurations of the database.
  • Flat-File vs. DBMS Approach

    • Flat-File System Drawbacks: Data redundancy across separate file systems, wasted storage space, and potential data inconsistency.
    • DBMS Approach Advantages: Centralized storage with single-copy data items, reduced redundancy, improved data integrity, shared multi-user access, and enhanced security.
    • DBMS Disadvantages: Large software size, high complexity requiring trained personnel, high initial/recurring costs, and severe failure impact requiring complex recovery.

Relational Model Foundations & Key Types

  • Database Models

    • Hierarchical Model: Data organized in a tree-like structure (single parent per node).
    • Network Model: Graph structure allowing nodes to have multiple parents.
    • Relational Model: Developed by E. F. Codd (19701970); based on relational set theory and two-dimensional tables. Modern implementations support cloud distributed architectures (e.g., Amazon RDS, Google Cloud SQL).
  • Strict Characteristics of a Relation (Table)

    • Entity Instance: Rows store data about one instance of an entity.
    • Attributes: Columns store attributes, each with a unique name within the table.
    • Atomic Cells: Each cell must hold a single value (no multi-valued attributes).
    • Domain Consistency: All values in a column must share the exact same data type.
    • Ordering: The sequence of rows and columns does not matter.
    • Uniqueness: No two rows in a table can be identical.
  • Key Classifications & Integrity Rules

    • Table 1. Key Classifications
    • Primary Key (PK): Uniquely identifies each row in a relation. Rule: Cannot be NULL and must be unique.
    • Candidate Key: Any attribute (or set of attributes) that is unique and non-NULL, making it a valid candidate for the PK.
    • Composite Key: A primary key composed of two or more columns combined.
    • Surrogate Key: An artificially generated numeric ID (e.g., AutoNumber) used when no natural candidate key exists.
    • Foreign Key (FK): A primary key from a parent table placed into a child table to represent a relationship.
    • Entity Integrity: Enforced by ensuring primary key values are unique and non-NULL, guaranteeing distinct entity instances.
    • Referential Integrity: Enforced by Foreign Keys; every FK value in a child table must match an existing PK value in the parent table (prevents orphaned records).
  • Schema Notation Rules

    • Table Name: Written in ALL CAPS.
    • Primary Key: Underlined.
    • Foreign Keys: Designated with FK references.
    • Example Notation: EMPLOYEE(EmpNo, EmpName, Address, PhoneNum, DeptNum) with FK DeptNum -> DEPARTMENT.

Entity-Relationship Diagrams (ERDs)

  • Conceptual Foundations & History

    • Origin: Introduced by Peter Chen (19761976) as a DBMS-independent conceptual modeling tool.
    • Naming Conventions: Entities must be singular, capitalized nouns (e.g., STORE, EMPLOYEE).
    • Diagram Symbols & Notation: Entities are represented as rectangles; attributes as ovals or listed fields within the rectangle; relationships as lines connecting entities.
  • Cardinality & Structural Symbols

    • Crow's Foot: Represents 'Many'.
    • Single Hash Mark: Represents 'One'.
    • Circle / Oval: Represents 'Optional' (zero).
    • Clockwise Reading: ERD relationship lines are evaluated in a clockwise sequence to form functional relationship statements.
  • Relationship Classification

    • Non-Identifying Relationship: Parent's PK becomes a standard Foreign Key in the child table (represented by a dashed line in Workbench).
    • Identifying Relationship: Parent's PK becomes part of the child table's Primary Key (represented by a solid line in Workbench).

Resolving Many-to-Many Relationships

  • The Structural Problem

    • Relational databases cannot directly implement a Many-to-Many (M-M) relationship due to the constraint against multi-valued cells.
  • The Resolution Strategy

    • Convert the M-M relationship into two 1-M relationships using an Associative Entity (also referred to as a Joining or Bridge table).
  • Structure of an Associative Table

    • Foreign Keys: Contains Foreign Keys referencing the Primary Keys of both parent entities.
    • Primary Key Structure: The Primary Key of the associative table is typically a Composite Key made of both Foreign Keys combined.
    • Intersection Attributes: Can hold attributes specific to the connection (e.g., Grade in a STUDENT_CLASS table).

SQL Implementation: DDL vs. DML

  • Data Definition Language (DDL)

    • Purpose: Defines, alters, or destroys database structures.
    • CREATE TABLE: Defines table columns, data types, and constraints. sql CREATE TABLE employee ( emp_id INT, first_name VARCHAR(25), last_name VARCHAR(25), salary DECIMAL(6,2), shelter_code CHAR(2), CONSTRAINT PRIMARY KEY (emp_id), CONSTRAINT FOREIGN KEY (shelter_code) REFERENCES shelter(shelter_code) );         
    • ALTER TABLE: Modifies existing structural definitions (e.g., ADD COLUMN, MODIFY COLUMN, DROP COLUMN).
    • DROP TABLE: Permanently removes a table structure from the database.
  • Common SQL Data Types

    • INT / INTEGER: Standard whole numbers.
    • VARCHAR(nn): Variable-length character strings up to nn characters.
    • CHAR(nn): Fixed-length character strings of length nn.
    • DECIMAL(m,dm, d): Exact numeric data where mm is total digits and dd is decimal places.
    • DATE: Calendar date formatted as YYYY-MM-DD.
  • Data Manipulation Language (DML)

    • Purpose: Used to query and modify rows within existing structures.
    • INSERT: Adds new records. sql INSERT INTO group_class (group_id, className, calories_burned) VALUES (10, 'Body Works Plus Abs', 500);         
    • UPDATE: Modifies existing field values (Caution: Omitting the WHERE clause updates every record in the table!). sql UPDATE employee SET salary = 5200 WHERE emp_id = 1;         
    • DELETE: Removes specific records (Caution: Omitting the WHERE clause deletes all records in the table!). sql DELETE FROM shelter WHERE shelter_code = 'L2';         
    • COMMIT: Permanently saves transaction changes to the database.

Self-Assessment Practice Questions

  • Question 1: Which property prevents a database column from storing a list of phone numbers in a single record?

    • Answer: The atomic cell rule of a relation (cells cannot hold multi-valued attributes).
  • Question 2: What is the structural difference between an identifying and a non-identifying relationship in an ERD?

    • Answer: In an identifying relationship (solid line), the parent's PK becomes part of the child's PK. In a non-identifying relationship (dashed line), the parent's PK acts only as a foreign key in the child.
  • Question 3: If a table ENROLLMENT uses (StudentID, CourseCRN) together as its Primary Key, what type of key is this?

    • Answer: A Composite Key.
  • Question 4: Why is a Foreign Key required in a 1-to-Many relationship? Which table receives it?

    • Answer: Foreign Keys establish logical links and enforce referential integrity. The PK of the parent table ('one' side) is placed as an FK into the child table ('many' side).
  • Question 5: What is the distinction between DDL and DML commands?

    • Answer: DDL (CREATE, ALTER, DROP) builds and modifies database structure. DML (INSERT, UPDATE, DELETE, SELECT) manages and manipulates row data within those structures.