SQL, Structured Query Language, is a programming language designed to manage data stored in relational databases. SQL operates through simple, declarative statements. This keeps data accurate and secure, and it helps maintain the integrity of databases, regardless of size.
Most of the actions you need to perform on a database are done with SQL statements.
SQL commands are grouped into four major categories depending on their functionality:
- Data Definition Language (DDL)
- Data Manipulation Language (DML)
- Transaction Control Language (TCL)
- Data Control Language (DCL)
SELECT statements are used to fetch data from a database (
extracts data from a database ). Every query will begin with SELECT.
ALTER TABLE table_name
ADD column_name datatype;
ALTER TABLE lets you add columns to a table in a database.
Modifies a table.
WHEN condition THEN 'Result_1'
WHEN condition THEN 'Result_2'
CASE statements are used to create different outputs (usually in the
SELECT statement). It is SQL’s way of handling if-then logic.
CREATE TABLE table_name (
CREATE TABLE creates a new table in the database. It allows you to specify the name of the table and the name of each column in the table.
We have an entire article on creating tables in MySQL. https://tutes.in/creating-a-table-in-phpmyadmin-xampp-server/
INSERT INTO table_name (column_1, column_2, column_3)
VALUES (value_1, 'value_2', value_3);
INSERT statements are used to add a new row to a table.
WHERE column_name operator value;
WHERE is a clause that filters the result set to include only rows where the specified condition is true.
SET some_column = some_value
WHERE some_column = some_value;
UPDATE statements allow you to edit rows in a table.
WHERE column_1 = value_1
AND column_2 = value_2;
AND is an operator that combines two conditions. Both conditions must be true for the row to be included in the result set.
WHERE column_name = value_1
OR column_name = value_2;
OR is an operator that filters the result set to only include rows where either condition is true.
These were the most common and basic SQL commands. There are many more commands in SQL.