DEV Community

Cover image for "SQL 101: Introduction to Structured Query Language."
Fiona Amolo Awuor
Fiona Amolo Awuor

Posted on

"SQL 101: Introduction to Structured Query Language."

As a beginner, I found my first class in SQL intriguing. Let's have a summary of what was taught.
What is SQL?
SQL stands for Structured Query Language and it's a standard programming language used for accessing and manipulating databases, especially in a relational database management system.
A relational database stores information in tabular form, with rows and columns each designated with different values.
SQL is used generally to maintain and optimize database performance. This language has different queries that are used to store, search, update, remove, delete, and retrieve information to help in data analysis.

How is SQL important?
It is considered versatile as it is used in all types of applications. Data analysts and developers use SQL as it blends well with other programming languages.
Components of an SQL system
SQL Table
This is the basic element of a relational database, and the tables usually consist of rows and columns. Database Engineers usually use tables to create relationships between different and many database tables to optimize data storage. For example, a table can be created using the following. Say we are creating a table called Users.

CREATE TABLE Users(
Id INT PRIMARY KEY NOT NULL,
Name VARCHAR (255) UNIQUE,
Email Address VARCHAR (255) UNIQUE
),
Enter fullscreen mode Exit fullscreen mode

SQL Statements
SQL statements, also referred to as SQL queries are instructions that a relational database understands.
Let's dive into SQL commands
These commands are specific keywords or SQL statements that data and systems analysts use to manipulate the data stored in various databases. The commands are categorized as:
Data Definition Language(DDL)
These commands design the database structure. Data Engineers and Analysts use DDL commands to create and modify database objects based on the requirements of a particular project. The CREATE command is used to create database objects such as databases, tables, and views. A data analyst must first create a database that will store data i.e

CREATE DATABASE db_name
Enter fullscreen mode Exit fullscreen mode

The above command will create a database that will be used to store tables and all types of data, enabling data analysis.

Data Query Language(DQL)
These commands are used to retrieve data stored in relational databases. The most common command for retrieving data is the SELECT statement, used for filtering and returning specific results from a database table.

Data Manipulation Language (DML)
These statements are used to add new information or modify the existing records in a table. The INSERT command is used to add and store new records in a database table. For instance, we would like to add new values to a table named Patients.

INSERT INTO Patients (Id, Name, Diagnosis)
VALUES (1, 'Awuor', 'Malaria')
Enter fullscreen mode Exit fullscreen mode

This command can be used to insert one or numerous records in a table.
The UPDATE command is a DML used to modify existing records in a table.

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Enter fullscreen mode Exit fullscreen mode

The DELETE statement deletes an unwanted record. The WHERE condition must be present when wanting to delete a record. If absent, all records will be deleted from the table.

DELETE FROM table_name WHERE condition;
Enter fullscreen mode Exit fullscreen mode

Data Control Language (DCL)
These commands are used by database administrators to manage or authorize database access for other users. The GRANT command is used to permit certain applications to manipulate one or multiple tables.

Top comments (1)

Collapse
 
allan-pg profile image
allan-pg

wonderful