SQL Commands
SQL Commands
Introduction
SQL stands for Structured Query Language. SQL commands are the
instructions used to communicate with a database to perform tasks, functions,
and queries with data.
SQL commands can be used to search the database and to do other functions
like creating tables, adding data to tables, modifying data, and dropping tables.
Here is a list of basic SQL commands (sometimes called clauses) you should
know if you are going to work with SQL
DDL (Data Definition Language)
The DDL Commands in Structured Query Language are used to create and
modify the schema of the database and its objects. The syntax of DDL
commands is predefined for describing the data. The commands of Data
Definition Language deal with how the data should exist in the database.
o CREATE
o ALTER
o DROP
o TRUNCATE
CREATE Command
CREATE is a DDL command used to create databases, tables, triggers and other
database object
Syntax :
CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,.
...]);
Example:
It is used to delete both the structure and record stored in the table.
Syntax
Example
ALTER Command
Syntax
Example
TRUNCATE Command
It is used to delete all the rows from the table and free the space containing the
table.
Syntax:
Example:
DML commands are used to modify the database. It is responsible for all form
of changes in the database.The command of DML is not auto-committed that
means it can't permanently save all the changes in the database. They can be
rollback.
o INSERT
o UPDATE
o DELETE
INSERT Command
The INSERT statement is a SQL query. It is used to insert data into the
row of a table.
Syntax :
Example :
INSERT INTO javatpoint (Author, Subject) VALUES ("Sonoo", "DBMS
");
UPDATE Command
Syntax:
Example :
UPDATE students
SET User_Name = 'Sonoo'
WHERE Student_Id = '3'
DELETE Command
Syntax:
Example :
DCL commands are used to grant and take back authority from any
database user.
o Grant
o Revoke
Syntax:
Example :
Syntax:
Example :
These operations are automatically committed in the database that's why they
cannot be used while creating tables or dropping them.
o COMMIT
o ROLLBACK
o SAVEPOINT
o
Syntax:
COMMIT;
Example:
DELETE FROM CUSTOMERS
WHERE AGE = 25;
COMMIT;
Syntax:
ROLLBACK;
Example:
DELETE FROM CUSTOMERS
WHERE AGE = 25;
ROLLBACK;
o SELECT
Syntax:
SELECT expressions
FROM TABLES
WHERE conditions;
Example:
SELECT emp_name
FROM employee
WHERE age > 20;