SQL Commands
SQL Commands
SQL Commands are like instructions to a table. It is used to interact with the database with
some operations. It is also used to perform specific tasks, functions, and queries of data. SQL
can perform various tasks like creating a table, adding data to tables, dropping the table, modifying
the table, set permission for users.
SQL Commands are mainly categorized into four categories:
Example of DDL
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
hire_date DATE
);
In this example, a new table called employees is created with columns for employee ID,
first name, last name, and hire date.
DQL Command
Command Description Syntax
It is used to retrieve data SELECT column1, column2, ...FROM
SELECT table_name WHERE condition;
from the database
Example of DQL
SELECT first_name, last_name, hire_date
FROM employees
WHERE department = 'Sales'
ORDER BY hire_date DESC;
This query retrieves employees’ first and last names, along with their hire dates, from the
employees table, specifically for those in the ‘Sales’ department, sorted by hire date.
Example of DML
INSERT INTO employees (first_name, last_name, department)
VALUES ('Jane', 'Smith', 'HR');
This query inserts a new record into the employees table with the first name ‘Jane’, last name
‘Smith’, and department ‘HR’.
Example of DCL
GRANT SELECT, UPDATE ON employees TO user_name;
This command grants the user user_name the permissions to select and update records in the
employees table.