Essay

SQL statement types

SQL stands for Structured Query Language and can be used to communicate with a relational database. Almost every backend developer should have had contact with one or other form of SQL depening on the underlying database system.

SQL Statement types

SQL statements can be grouped into three main groups:

  • Data Definition Language (DDL) - We can use DDL statements to interact with the database in order to create, modify, and delete tables and other database objects from the database. Some of the common DDL statements are:
StatementUsage
CREATETo create a new database object, like a table, view or stored procedure
ALTERTo modify an existing database object, for example changing type of a column of a table
RENAMETo rename an existing database object
DROPTo drop/delete an existing database object

Table 1: Common DDL Statements

Example Create Statement
CREATE TABLE Person
(
    ID INT PRIMARY KEY,
    Name VARCHAR(40) NOT NULL,
    Age DECIMAL NULL,
    Country VARCHAR(128) NOT NULL,
);

The datatypes that are avialable for columns may differ from one database system to another.

  • Data Control Language (DCL) - We can use DCL statements to manage access to objects in a database. Some of the common DCL statements are:
StatementUsage
GRANTTo grant permission to a database object to perform a specific action or actions
DENYTo deny permission to a database object to perform a specific action or actions
REVOKETo revoke a previously granted permission

Table 1: Common DCL Statements

Example Grant Statement
GRANT SELECT, INSERT
ON Person
TO user1;
  • Data Manipulation Language (DML) - We can use DML statements to manipulate the rows of data in the tables. They enable us to create new rows, retrieve, modify or delete existing rows as well. These are also the most commonly used statements. Some of the common DML statements are:
StatementUsage
INSERTTo create a new row in a table
SELECTTo read rows from a table
DELETETo delete existing rows from a table
UPDATETo modfiy existing rows in a table

Table 1: Common DML Statements

Example Select Statement
SELECT *
FROM Person
WHERE Name = 'Example';