0% found this document useful (0 votes)
2 views3 pages

SQL Commands

SQL Commands are instructions used to interact with databases, allowing for operations such as creating, modifying, and querying data. They are categorized into four types: DDL (Data Definition Language), DQL (Data Query Language), DML (Data Manipulation Language), and DCL (Data Control Language). Each category has specific commands for managing database structures, retrieving data, manipulating data, and controlling access permissions.

Uploaded by

haportugal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
2 views3 pages

SQL Commands

SQL Commands are instructions used to interact with databases, allowing for operations such as creating, modifying, and querying data. They are categorized into four types: DDL (Data Definition Language), DQL (Data Query Language), DML (Data Manipulation Language), and DCL (Data Control Language). Each category has specific commands for managing database structures, retrieving data, manipulating data, and controlling access permissions.

Uploaded by

haportugal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 3

What are 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:

• DDL – Data Definition Language


• DQL – Data Query Language
• DML – Data Manipulation Language
• DCL – Data Control Language

1. Data Definition Language (DDL) in SQL


DDL or Data Definition Language actually consists of the SQL commands that can be used
to defining, altering, and deleting database structures such as tables, indexes, and schemas. It
simply deals with descriptions of the database schema and is used to create and modify the
structure of database objects in the database.
Common DDL Commands

Command Description Syntax


Create database or its
objects (table, index, CREATE TABLE table_name (column1
CREATE data_type, column2 data_type, ...);
function, views, store
procedure, and triggers)
Delete objects from the
DROP DROP TABLE table_name;
database
Alter the structure of the ALTER TABLE table_name ADD COLUMN
ALTER column_name data_type;
database
Remove all records from
a table, including all TRUNCATE TABLE table_name;
TRUNCATE
spaces allocated for the
records are removed
Add comments to the COMMENT 'comment_text' ON TABLE
COMMENT table_name;
data dictionary
Rename an object RENAME TABLE old_table_name TO
RENAME new_table_name;
existing in the database

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.

2. Data Query Language (DQL) in SQL


DQL statements are used for performing queries on the data within schema objects. The
purpose of the DQL Command is to get some schema relation based on the query passed to it.
This command allows getting the data out of the database to perform operations with it. When a
SELECT is fired against a table or tables the result is compiled into a further temporary table,
which is displayed or perhaps received by the program.

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.

3. Data Manipulation Language (DML) in SQL


The SQL commands that deal with the manipulation of data present in the database belong to
DML or Data Manipulation Language and this includes most of the SQL statements. It is the
component of the SQL statement that controls access to data and to the database. Basically,
DCL statements are grouped with DML statements.
Commond DML Commands

Command Description Syntax


INSERT INTO table_name (column1,
INSERT Insert data into a table column2, ...) VALUES (value1,
value2, ...);
UPDATE table_name SET column1 =
Update existing data value1, column2 = value2 WHERE
UPDATE
within a table condition;
Delete records from a DELETE FROM table_name WHERE
DELETE condition;
database table
Table control LOCK TABLE table_name IN lock_mode;
LOCK
concurrency
Call a PL/SQL or JAVA
CALL CALL procedure_name(arguments);
subprogram
EXPLAIN Describe the access path EXPLAIN PLAN FOR SELECT * FROM
PLAN to data table_name;

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’.

4. Data Control Language (DCL) in SQL


DCL (Data Control Language) includes commands such as GRANT and REVOKE which 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


Assigns new privileges to
GRANT privilege_type
a user account, allowing
[(column_list)] ON [object_type]
GRANT access to specific object_name TO user [WITH GRANT
database objects, OPTION];
actions, or functions.
Removes previously
granted privileges from a REVOKE [GRANT OPTION FOR]
user account, taking privilege_type [(column_list)] ON
REVOKE [object_type] object_name FROM user
away their access to
certain database objects [CASCADE];
or actions.

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.

You might also like