120
SQL DELETE Statement
The SQL DELETE statement is used to delete rows from a table. Generally, DELETE statement removes one or more records form a table.
Syntax
Sample Table
EMPLOYEE
EMP_ID | EMP_NAME | CITY | SALARY | AGE |
---|---|---|---|---|
1 | Angelina | Chicago | 200000 | 30 |
2 | Robert | Austin | 300000 | 26 |
3 | Christian | Denver | 100000 | 42 |
4 | Kristen | Washington | 500000 | 29 |
5 | Russell | Los angels | 200000 | 36 |
6 | Marry | Canada | 600000 | 48 |
Deleting Single Record
Delete the row from the table EMPLOYEE where EMP_NAME = ‘Kristen’. This will delete only the fourth row.
Query
Output: After executing this query, the EMPLOYEE table will look like:
EMP_ID | EMP_NAME | CITY | SALARY | AGE |
---|---|---|---|---|
1 | Angelina | Chicago | 200000 | 30 |
2 | Robert | Austin | 300000 | 26 |
3 | Christian | Denver | 100000 | 42 |
5 | Russell | Los angels | 200000 | 36 |
6 | Marry | Canada | 600000 | 48 |
Deleting Multiple Record
Delete the row from the EMPLOYEE table where AGE is 30. This will delete two rows(first and third row).
Query
Output: After executing this query, the EMPLOYEE table will look like:
EMP_ID | EMP_NAME | CITY | SALARY | AGE |
---|---|---|---|---|
2 | Robert | Austin | 300000 | 26 |
3 | Christian | Denver | 100000 | 42 |
5 | Russell | Los angels | 200000 | 36 |
6 | Marry | Canada | 600000 | 48 |
Delete all of the records
Delete all the row from the EMPLOYEE table. After this, no records left to display. The EMPLOYEE table will become empty.
Syntax
Query
Output: After executing this query, the EMPLOYEE table will look like:
EMP_ID | EMP_NAME | CITY | SALARY | AGE |
---|
Note: Using the condition in the WHERE clause, we can delete single as well as multiple records. If you want to delete all the records from the table, then you don’t need to use the WHERE clause.
Next TopicDBMS SQL View