Relational Databases

Understanding Relational Databases

  • Relational databases are a type of structured database in which data is stored in related tables.
  • Each table in a relational database represents a collection of related data items.
  • These tables are made up of rows, which represent individual records, and columns, which represent attributes or characteristics of those records.
  • The term ‘relational’ refers to the relationship between the data items stored in different tables.

Keys in Relational Databases

  • An important feature of relational databases is the use of keys. These are special fields that allow the database to maintain its relationships.
  • A primary key is a unique identifier for a record in a table. This can be something like a customer ID, a student number or a product code.
  • A foreign key is a field in one table that uniquely identifies a record in another table. Foreign keys are used to link tables together.

Relationships in Relational Databases

  • Relationships between tables can be one-to-one, one-to-many, or many-to-many.
  • A one-to-one relationship means that each record in one table corresponds to one record in another table.
  • A one-to-many relationship means that a record in one table can relate to multiple records in another.
  • A many-to-many relationship requires a third linking table, as each record in the first table can relate to multiple records in the second table and vice versa.

Structured Query Language (SQL)

  • To interact with a relational database, you use a standardised language known as SQL, which stands for Structured Query Language.
  • With SQL, you can execute a variety of tasks such as creating tables, inserting data into tables, updating existing data, deleting data, or retrieving data from the database.

Normalisation

  • Normalisation is a methodology in relational databases used to minimise data redundancy and avoid data anomalies.
  • It involves the process of organising the data into tables so that the dependency on the primary key is upheld.

Benefits of Relational Databases

  • Relational databases offer many benefits, including data integrity, security, and flexibility.
  • They support ACID properties (Atomicity, Consistency, Isolation, Durability) which are crucial for maintaining the data integrity.
  • They have strong security features, allowing administrators to set up permissions and restrict access to certain data.
  • They offer flexibility in data retrieval and manipulation thanks to SQL, allowing you to perform complex queries.