navigation

DELETE

The SQL DELETE statement is used to delete the existing records from a table.
Syntax:
Basic syntax of DELETE statement is as follows:
DELETE FROM table_name
WHERE [condition];
You can combine N number of conditions.

NP: 
You can use WHERE clause with UPDATE query to update selected rows. If you do not include the WHERE clause, column values for all the rows get affected.

Example:
Below is the "EMPLOYEE1" table:

ID
NAME
START_DATE
END_DATE
SALARY
CITY
1
A
01/01/2016 00:00:00
01/06/2016 00:00:00
10,000
CHENNAI
2
B
02/01/2016 00:00:00
07/03/2016 00:00:00
10,000
BOMBAY
3
C
03/01/2016 00:00:00
08/06/2016 00:00:00
10,000
DELHI
4
D
01/01/2016 00:00:00
07/06/2016 00:00:00
10,000
PUNE
5
E
01/01/2016 00:00:00
09/06/2016 00:00:00
10,000
NOIDA
6
F
01/01/2016 00:00:00
08/06/2016 00:00:00
10,000
BHUBANESWAR
7
G
01/01/2016 00:00:00
07/06/2016 00:00:00
10,000
HYDERABAD
8
H
01/01/2016 00:00:00
06/06/2016 00:00:00
10,000
KOLKATA

1) DELETE an employee from EMPLOYEE1 table, whose ID is 8:

DELETE FROM  EMPLOYEE1
WHERE ID = 8;

ID
NAME
START_DATE
END_DATE
SALARY
CITY
1
A
01/01/2016 00:00:00
01/06/2016 00:00:00
10,000
Pune
2
B
02/01/2016 00:00:00
07/03/2016 00:00:00
10,000
Pune
3
C
03/01/2016 00:00:00
08/06/2016 00:00:00
10,000
Pune
4
D
01/01/2016 00:00:00
07/06/2016 00:00:00
10,000
Pune
5
E
01/01/2016 00:00:00
09/06/2016 00:00:00
10,000
Pune
6
F
01/01/2016 00:00:00
08/06/2016 00:00:00
10,000
Pune
7
G
01/01/2016 00:00:00
07/06/2016 00:00:00
10,000
Pune

2)To delete all the records from ‘EMPLOYEE1’ table, 

DELETE FROM EMPLOYEE1;

ID
NAME
START_DATE
END_DATE
SALARY
CITY



No comments:

Post a Comment