Database Management Systems: Keys, Entities, and Normalization

Types of Keys in SQL

In SQL, a key is used to identify a record in a database table. There are several types of keys:

  • Primary Key: Uniquely identifies each record in a table. Each table can have only one primary key.
  • Foreign Key: A column or a set of columns in one table that refers to the primary key of another table. It is used to establish relationships between tables.
  • Candidate Key: A set of attributes that could uniquely identify a record in a table. A table can have multiple candidate keys.
  • Alternate Key: A candidate key that is not selected as the primary key.
  • Composite Key: A key that consists of two or more columns used to uniquely identify a record.
  • Unique Key: Ensures that all values in a column are different, but unlike the primary key, a table can have more than one unique key.
  • Surrogate Key: A unique identifier for an entity, usually a system-generated value (like an auto-incremented number).

Entities in DBMS

An entity, in the context of a Database Management System (DBMS), refers to any object or thing in the real world that has an independent existence. An entity can be a person, place, thing, or concept about which data is stored. For example, in a school database, “Student” and “Course” could be entities.

What is a DBMS?

DBMS (Database Management System) is software used to store, manage, and manipulate data in a structured way. It provides an interface for users to interact with the data and supports features like data security, integrity, and backup. Common DBMS examples are MySQL, PostgreSQL, Oracle, and SQL Server.

What is an RDBMS?

RDBMS (Relational Database Management System) is a type of DBMS that stores data in the form of tables (relations). In an RDBMS, data is organized into rows and columns, and relationships between the data are established using foreign keys. Popular RDBMS examples include MySQL, Oracle, and SQL Server.

Relational Model

The Relational Model is a way of structuring data in a database as a collection of relations (tables). Each relation consists of rows (tuples) and columns (attributes). Data in different relations can be related through keys, particularly foreign keys, which link rows from different tables. It forms the foundation for RDBMS.

Normalization in DBMS

Normalization is the process of organizing the data in a database to reduce redundancy and dependency. The goal is to separate data into different tables so that it can be stored more efficiently and to ensure that relationships between the data are logically sound. It involves breaking down large tables into smaller, manageable ones while maintaining relationships between them.

Types of Normalization

There are several Normal Forms (NF), each representing a level of normalization:

  • First Normal Form (1NF): Ensures that each column contains atomic values (no multiple values in a single column) and each record is unique.
  • Second Normal Form (2NF): Meets the criteria for 1NF and also removes partial dependencies (i.e., all non-key attributes must depend on the entire primary key).
  • Third Normal Form (3NF): Meets the criteria for 2NF and eliminates transitive dependencies (i.e., non-key attributes must not depend on other non-key attributes).
  • Boyce-Codd Normal Form (BCNF): A stricter version of 3NF, where every determinant (an attribute that determines the value of another attribute) is a candidate key.
  • Fourth Normal Form (4NF): Removes multi-valued dependencies, meaning that a record should not contain multiple independent facts about the same entity.
  • Fifth Normal Form (5NF): Ensures that a table is decomposed into smaller tables such that all data dependencies are maintained, and there is no loss of information.