Introduction to SQL

Learn about SQL and how it’s used to manipulate and access databases.

Overview of SQL

SQL (Structured Query Language) is a language used to manage data in relational database systems. To be good at working with SQL, we should have a proper understanding of the kind of relationships that exist between the entities. This helps us write more efficient, maintainable, and scalable code.

These relationships can be:

  • one-to-many
  • many-to-many
  • one-to-one
  • many-to-one

SQL is one of the most widely used relational databases and provides a well-defined structure for handling and querying data.

Overview of SQL relationships

One-to-one

In SQL, a one-to-one relationship is the relationship that exists between records of two tables where one record maps to another one uniquely. A one-to-one is a lot like a relationship that exists between an employee and the employee’s office—one in which a company assigns only a single office per employee.

Many-to-one

A many-to-one or a one-to-many relationship is a relationship in which one record in an SQL table maps to many other records in a different table. A good illustration of this is the relationship that exists between the company and its employees. Many people (the employees) can belong to one company, and one company can have many employees.

To achieve this in the SQL, a foreign key column is added to either of the tables that map to the primary key of the other table.

Below we have two separate tables for the company and employees:

Get hands-on with 1200+ tech skills courses.