SQL Commands
SQL Commands
For example − Employee name, Product name, Name of the student, Marks
of the student, Mobile number, Image etc.
Information
Information is the data that has been converted into more useful or
intelligent form.
DBMS RDBMS
1
DBMS RDBMS
The main differences are: RDBMS stores data in the form of tables,
whereas DBMS stores data in the form of files. Single users are
2
supported by DBMS, whereas multiple users are supported by
RDBMS. Client-server architecture is not supported by DBMS,
although it is supported by RDBMS.
SQL COMMANDS
o CREATE
o ALTER
o DROP
o TRUNCATE
b. DROP: It is used to delete both the structure and record stored in the table.
Syntax
1. DROP TABLE table_name;
Example
1. DROP TABLE EMPLOYEE;
c. ALTER: It is used to alter the structure of the database. This change could be either to modify the
characteristics of an existing attribute or probably to add a new attribute.
Syntax:
To add a new column in the table
1. ALTER TABLE table_name ADD column_name COLUMN-definition;
To modify existing column in the table:
1. ALTER TABLE table_name MODIFY(column_definitions....);
EXAMPLE
3
d. TRUNCATE: It is used to delete all the rows from the table and free the space containing the table.
Syntax:
Example:
o INSERT
o UPDATE
o DELETE
a. INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of
a table.
Syntax:
1. INSERT INTO TABLE_NAME Values( (value1, value2, value3, .... valueN);
For example:
b. UPDATE: This command is used to update or modify the value of a column in the
table.
Syntax:
1. UPDATE table_name SET [column_name1= value1,...column_nameN = valueN] [WHERE C
ONDITION]
For example:
1. UPDATE students SET User_Name = 'Sonoo' WHERE Student_Id = '3'
c. DELETE: It is used to remove one or more row from a table.
Syntax:
1. DELETE FROM table_name [WHERE condition];
For example:
1. DELETE FROM javatpoint
2. WHERE Author="Sonoo";
4
DCL commands are used to grant and take back authority from any database user.
Here are some commands that come under DCL:
Learn more
o Grant
o Revoke
TCL commands can only use with DML commands like INSERT, DELETE and UPDATE only.
These operations are automatically committed in the database that's why they cannot be used wh
creating tables or dropping them.
Here are some commands that come under TCL:
o COMMIT
o ROLLBACK
o SAVEPOINT
a. Commit: Commit command is used to save all the transactions to the database.
Syntax:
COMMIT;
Example:
b. Rollback: Rollback command is used to undo transactions that have not already been saved to t
database.
Syntax:
ROLLBACK;
Example:
5
WHERE AGE = 25;
ROLLBACK;
c. SAVEPOINT: It is used to roll the transaction back to a certain point without rolling back the entir
e transaction.
Syntax:
SAVEPOINT SAVEPOINT_NAME;
o SELECT
a. SELECT: This is the same as the projection operation of relational algebra. It is used to select t
attribute based on the condition described by WHERE clause.
Syntax:
SELECT expressions
FROM TABLES
WHERE conditions;
For example: