What is SQL? How it works?

Yash Nalavade
3 min readApr 19, 2023

--

Introduction

Structured Query Language (SQL) is a programming language used to manage and change relational databases. Because it is powerful, flexible, and easy to use, it is the language of choice for many database administrators, data analysts, and developers. This article will explain what SQL is, how it works, and how it can be used to communicate with relational databases in different ways.

Yash Nalavade — SQL — What is SQL? How it works?

What does SQL mean?

SQL is a standard language for communicating with databases. It is a language that is made for working with data in tables. IBM created the language in the 1970s, and since then it has grown to become the most popular language for working with databases.

How does SQL work?

Using SQL to talk to databases is done through “queries.” A query is a command that is sent to the database. It is used to get data out of the database, change it, or analyze it. Data Manipulation Language (DML) queries and Data Definition Language (DDL) queries are the two main types of SQL queries.

Data Manipulation Language (DML) queries are used to get data out of tables, change it, or get rid of it. SELECT, INSERT, UPDATE, and DELETE are the DML queries that are used the most.

You can use SELECT queries to get data from one or more tables. They can be used to retrieve specific columns or all columns in a table. SELECT queries can also be used to filter data based on specific criteria using a WHERE clause.

INSERT queries are used to insert new data into tables. They are used to add new records to a table by specifying the values for each column.

UPDATE queries are used to modify existing data in tables. They are used to change the values of one or more columns in a table.

DELETE queries are used to delete data from tables. They are used to remove records from a table based on specific criteria.

Data Definition Language (DDL) queries are used to create and modify the structure of tables. Some of the most commonly used DDL queries include CREATE TABLE, ALTER TABLE, and DROP TABLE.

CREATE TABLE queries are used to create new tables. They are used to define the columns and data types for each column in the table.

ALTER TABLE queries are used to modify existing tables. They are used to add or remove columns, modify column data types, and modify table constraints.

DROP TABLE queries are used to delete tables. They are used to remove entire tables from a database.

SQL syntax

SQL has a specific syntax that must be followed in order to write correct queries.

The basic syntax for a SELECT query is as follows:

SELECT column1, column2, ... 
FROM table_name
WHERE condition;

This query selects one or more columns from a table and returns the data that meets the specified condition.

The basic syntax for an INSERT query is as follows:

INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);

This query inserts a new record into a table and specifies the values for each column.

The basic syntax for an UPDATE query is as follows:

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

This query modifies the values of one or more columns in a table based on the specified condition.

The basic syntax for a DELETE query is as follows:

DELETE FROM table_name WHERE condition;

Try out this example for better understanding :

CREATE TABLE customers (
id INT PRIMARY KEY,
name VARCHAR(50),
email VARCHAR(50),
phone VARCHAR(20)
);
INSERT INTO customers (id, name, email, phone)
VALUES (1, 'John Smith', 'john@example.com', '123-456-7890'),
(2, 'Jane Doe', 'jane@example.com', '987-654-3210'),
(3, 'Bob Johnson', 'bob@example.com', '555-555-1212');
SELECT * FROM customers;

UPDATE customers SET email = 'jane.doe@example.com' WHERE id = 2;

SELECT * FROM customers;

DELETE FROM customers WHERE id = 3;

SELECT * FROM customers;Yash Nalavade LinkedIn

If you have any further suggestions or questions, feel free to let me know.

LinkedIn — Yash Nalavade

--

--