delete command
Helps us to delete records from an existing table.
Can be used in two ways
1. to delete all the records
2. to delete selected records (condition has to be specified)
(i). to delete all the records
Syntax:
Delete from tablename;
Note: all the records will be deleted but structure of the table will remain intact.(i.e. structure will not be deleted)
Example:
delete from std;
delete from emp;
(ii) to delete selected records
In order to delete selected records we have to apply a condition. The records/tuples which satisfy the condition are deleted.
Syntax:
Delete from tablename where condition;
Example:
delete from std where roll=101;
delete from std where age<18;
Example Queries:
1. To delete record of amit
Sol:
Delete from std where name=’amit’;
2. Delete records of all employees working in production and sales department.
Sol:
Delete from employee where deptname=’production’ or deptname=’sales’;
3. Delete records of amit,sumit and rohit.
Sol:
Delete from std where name=’amit’ or name=’sumit’ or name=’rohit’;
4. Delete record of manager named rohit who gets salary more then 45000
Sol:
Delete from employee
Where name=’rohit’ and design=’manager’ and sal>45000;
5. Company decides to terminate all programmers of sales department.
Sol:
Delete from employee
Where design=’programmer’ and deptname=’sales’;