SQL Commands
SQL Commands
SQL Commands:
The commands in SQL are called Queries and they are of two types
Example:
CREATE TABLE EMPLOYEE(Name VARCHAR2(20), Email VARCHAR2(100), DOB
DATE);
B. DROP:- It is used to delete both the structure and record stored in the table.
Syntax :
DROP TABLE table_name;
Example :
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
ALTER TABLE table_name ADD column_name COLUMN-definition;
To modify existing column in the table
ALTER TABLE table_name MODIFY(column_definitions....);
EXAMPLE
ALTER TABLE STU_DETAILS ADD(ADDRESS VARCHAR2(20));
ALTER TABLE STU_DETAILS MODIFY (NAME VARCHAR2(20));
D. TRUNCATE:- It is used to delete all the rows from the table and free the space
containing the table.
Syntax:
TRUNCATE TABLE table_name;
Example:
TRUNCATE TABLE EMPLOYEE;
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.
• INSERT
• UPDATE
• DELETE
A. INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of a
table.
• Syntax:
Or
INSERT INTO TABLE_NAME
• For example:
INSERT INTO javatpoint (Author, Subject) VALUES ("Sonoo", "DBMS");
B. UPDATE: This command is used to update or modify the value of a column in the table.
• Syntax:
• For example:
UPDATE students
• Syntax:
DELETE FROM table_name [WHERE condition];
• For example:
DELETE FROM javatpoint
WHERE Author="Sonoo";
• Grant
• Revoke
• Example
These operations are automatically committed in the database that's why they cannot be
used while creating tables or dropping them.
A. Commit:- Commit command is used to save all the transactions to the database.
• Syntax:
COMMIT;
• Example:-
DELETE FROM CUSTOMERS
COMMIT;
B. Rollback:- Rollback command is used to undo transactions that have not already been saved to
the database.
• Syntax:
ROLLBACK;
• Example:
DELETE FROM CUSTOMERS
WHERE AGE = 25;
ROLLBACK;
c. SAVEPOINT:- It is used to roll the transaction back to a certain point without rolling back the
entire transaction.
• Syntax:
SAVEPOINT SAVEPOINT_NAME;
SELECT
A. SELECT:- This is the same as the projection operation of relational algebra. It is used to select
the attribute based on the condition described by WHERE clause.
• Syntax:
SELECT expressions
FROM TABLES
WHERE conditions;
• For example:
SELECT emp_name
FROM employee