DBMS Languages: -
DDL (Data Definition Language): -
Common DDL Commands
Command Description Syntax
Create database or its
objects (table, index, CREATE TABLE table_name
CREATE function, views, store (column1 data_type, column2
procedure, and data_type, ...);
triggers)
Delete objects from
DROP DROP TABLE table_name;
the database
ALTER TABLE table_name ADD
Alter the structure of
ALTER COLUMN column_name
the database data_type;
Command Description Syntax
Remove all records
from a table, including
TRUNCATE all spaces allocated TRUNCATE TABLE table_name;
for the records are
removed
Add comments to the COMMENT 'comment_text' ON
COMMENT TABLE table_name;
data dictionary
Rename an object
RENAME TABLE old_table_name
RENAME existing in the TO new_table_name;
database
Example:
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
hire_date DATE
);
DQL - Data Query Language
DQL statements are used for performing queries on the data within
schema objects.
DQL Command
Command Description Syntax
SELECT column1,
It is used to retrieve data
SELECT column2, ...FROM table_name
from the database WHERE condition;
DML - Data Manipulation Language
Common DML Commands
Command Description Syntax
INSERT INTO table_name (column1,
Insert data into a
INSERT column2, ...) VALUES (value1, value2,
table ...);
Update existing UPDATE table_name SET column1 =
UPDATE data within a value1, column2 = value2 WHERE
table condition;
Delete records
DELETE FROM table_name WHERE
DELETE from a database condition;
table
Table control
LOCK LOCK TABLE table_name IN lock_mode;
concurrency
Call a PL/SQL or
CALL JAVA CALL procedure_name(arguments);
subprogram
Describe the
EXPLAIN EXPLAIN PLAN FOR SELECT * FROM
access path to table_name;
PLAN
data
Example:
INSERT INTO employees (first_name, last_name, department)
VALUES ('Jane', 'Smith', 'HR');
DCL - Data Control Language
mainly deal with the rights, permissions and other controls of the database
system. These commands are used to control access to data in the
database by granting or revoking permissions.
Common DCL Commands
Command Description Syntax
GRANT Assigns new privileges GRANT privilege_type
to a user account, [(column_list)] ON
allowing access to [object_type] object_name
TO user [WITH GRANT
specific database OPTION];
objects, actions, or
Command Description Syntax
functions.
Removes previously
granted privileges REVOKE [GRANT OPTION FOR]
from a user account, privilege_type
REVOKE taking away their [(column_list)] ON
access to certain [object_type] object_name
database objects or FROM user [CASCADE];
actions.
Example of DCL
GRANT SELECT, UPDATE ON employees TO user_name;
TCL - Transaction Control Language
Common TCL Commands
Command Description Syntax
BEGIN BEGIN TRANSACTION
Starts a new transaction [transaction_name];
TRANSACTION
Saves all changes made
COMMIT COMMIT;
during the transaction
Undoes all changes
ROLLBACK made during the ROLLBACK;
transaction
Creates a savepoint
SAVEPOINT
SAVEPOINT within the current savepoint_name;
transaction
Example:
BEGIN TRANSACTION;
UPDATE employees SET department = 'Marketing' WHERE
department = 'Sales';
SAVEPOINT before_update;
UPDATE employees SET department = 'IT' WHERE department =
'HR';
ROLLBACK TO SAVEPOINT before_update;
COMMIT;
Most Important SQL Commands
Command Description
SELECT Retrieves data from one or more tables.
INSERT Adds new rows (records) to a table.
UPDATE Modifies existing data in a table.
DELETE Removes specific rows from a table.
CREATE TABLE Creates a new table in the database.
Modifies the structure of an existing table (e.g., add or
ALTER TABLE
remove columns).
DROP TABLE Permanently deletes a table and its data.
TRUNCATE Removes all rows from a table but keeps its structure
TABLE intact.
WHERE Filters records based on a condition.
ORDER BY Sorts the result set in ascending or descending order.
Groups rows that have the same values in specified
GROUP BY
columns.
HAVING Filters grouped data (used with GROUP BY).
Combines rows from two or more tables based on a
JOIN
related column.
DISTINCT Removes duplicate values from the result set.
IN / BETWEEN /
Used for advanced filtering conditions.
LIKE
Command Description
UNION Combines the result of two or more SELECT queries.
GRANT Gives user privileges or permissions.
REVOKE Removes user privileges.
COMMIT Saves all changes made in the current transaction.
Undoes changes if something goes wrong in a
ROLLBACK
transaction.
SAVEPOINT Sets a point in a transaction to roll back to if needed.