DEV Community

Brigit Melbride
Brigit Melbride

Posted on

SQL 101: Introduction to Structured Query Language

Introduction
SQL is a standard language for database creation and manipulation. It is the standard language for relational database management systems.

SQL is used to create a database, define its structure, implement it, and perform various functions on the database.

It's also used for accessing, maintaining, and manipulating already created databases. It enables you to enter, modify and extract data in a database.

WHY YOU SHOULD LEARN SQL
SQL is a crucial skill across a wide range of industries hence one of the most important tools used in data management.

SQL is a critical skill across a wide range of industries, making it one of the most important tools for data management. Whether it's for managing financial transactions, healthcare records, or tech backend systems, SQL allows organizations to access, manipulate, and analyze data effectively.
Some fields where SQL is commonly used include:

  • Finance: Manage transactions, customer accounts, and compliance records.
  • Healthcare: Maintain patient records, manage appointments, and track billing information.
  • Tech Industry: Store user information, manage data in applications, and power backend systems

Regardless of the industry, SQL is indispensable for data-driven decision-making.

CAREER OPPORTUNITIES IN SQL
Mastering SQL can open up several career paths, including:

  • Data Scientist: Examines and interprets large amounts of data to provide valuable statistical insights using complex data modeling techniques.
  • Data Analyst: Collects, evaluates, and interprets data to find trends and patterns, enabling better decision-making.
  • Business Analyst: Combines IT and business development skills to provide tailored solutions that meet business requirements.
  • Database Administrator: Manages and maintains company databases, ensuring data security and easy access.
  • SQL Developer: Designs, builds, and maintains databases for clients, often creating custom database applications.

These are just a few examples of the many career opportunities that SQL offers in today’s data-driven world.

By mastering SQL, individuals can work with databases to perform essential operations, from managing large datasets to conducting complex analyses, which are critical in today's data-driven world.

BASIC CONCEPTS OF SQL

Databases and Tables

A database is a structured collection of data that allows for easy access, management, and updating. Data within a database is stored in tables, which consist of columns and rows:

  • Columns represent attributes of the data (e.g., name, age).
  • Rows represent individual records or entries in the table.
CREATE DATABASE School;
USE School;

CREATE TABLE Students (
    name TEXT,
    age INT
);

INSERT INTO Students(name, age)
VALUES ('Melbride', 20);
Enter fullscreen mode Exit fullscreen mode

In the above we create a database named School, then a table Students with two columns (name, age). Finally, we insert a new student record (Melbride, 20).

SQL Syntax

SQL uses commands to interact with data stored in tables. Commands like SELECT, INSERT, UPDATE, and DELETE allow you to perform actions on your data. SQL statements must end with a semicolon (;) to mark the end of the command.

SELECT Name, Email FROM Customers WHERE CustomerID = 1;

Enter fullscreen mode Exit fullscreen mode

The above command retrieves the Name and Email of the customer with CustomerID equal to 1.

Common SQL Commands

Here are some commonly used SQL commands that are essential for interacting with databases:

  • SELECT: Retrieves data from one or more tables.
  • INSERT: Adds new data into a table.
  • CREATE: Creates a new table or database.
  • DROP: Deletes a table or database
  • UPDATE: Modifies existing data within a table
  • DELETE: Removes data from a table.
SELECT * FROM Students;
INSERT INTO Students(name, age) VALUES ('Brigit', 20);
UPDATE Students SET age = 21 WHERE name = 'Melbride';
DELETE FROM Students WHERE name = 'Brigit';
Enter fullscreen mode Exit fullscreen mode

Introduction to SQL Functions

SQL also supports various functions that allow you to perform calculations and data analysis:

  • COUNT(): Counts the number of rows in a result set.
  • SUM(): Calculates the total sum of a column.
  • AVG(): Computes the average value of a column.
  • MAX(): Finds the lowest value in a column.
  • MIN(): Finds the highest value in a column.
SELECT COUNT(*) FROM Students;
SELECT AVG(age) FROM Students;
SELECT MAX(age) FROM Students;
Enter fullscreen mode Exit fullscreen mode

Having a basic understanding of SQL, will help you to practice the simple queries and gradually explore more complex database concepts like indexing, normalization, and performance optimization. SQL is a powerful tool, and mastery comes through hands-on experience.

Top comments (0)