
Deleting rows in a table
Syntax
Purpose
To remove rows from a table.
Prerequisites
For you to delete rows from a table, the table must be in your own schema or you must have DELETE privilege on the table.
The DELETE ANY TABLE system privilege also allows you to delete rows from any table.
Keywords and Parameters
schema
is the schema containing the table. If you omit schema, Oracle assumes the table or view is in your own schema.
table
is the name of a table from which the rows are to be deleted.
where_clause
deletes only rows that satisfy the condition. The condition can reference the table and can contain a subquery..
If you omit the where_clause, Oracle deletes all rows of the table or view.
t_alias
provides a correlation name for the table to be referenced elsewhere in the statement. Table aliases are generally used in DELETE statements with correlated queries.
Examples
Basic Examples
The following statement deletes all rows from a table named DEPARTMENT.
DELETE FROM DEPARTMENT;
The following statement deletes from the TEACHER table all professors who have less than 100 Commission:
DELETE FROM TEACHER
WHERE post = 'professor' AND Commission < 100;
Lab tasks
Inserting rows in tables
Insert the following rows in tables.
FACULTY |
FacNo |
Name |
Dean |
Building |
Fund |
|
1 |
informatics |
Sidorov |
5 |
57398.00 |
|
2 |
economy |
Petrov |
3 |
NULL |
|
3 |
linguistics |
Popov |
4 |
NULL |
DEPARTMENT |
DepNo |
FacNo |
Name |
Head |
Building |
Fund |
|
1 |
1 |
SE |
Sidorov |
5 |
14378.00 |
|
2 |
1 |
CAD |
Perov |
5 |
15000.00 |
|
3 |
1 |
DBMS |
Ivanov |
4 |
22000.00 |
|
4 |
2 |
Accounts |
John |
3 |
NULL |
TEACHER |
TchNo |
DepNo |
Name |
Post |
Tel |
Hiredate |
Salary |
Commission |
|
1 |
1 |
Andrew |
assistant |
2281319 |
01.02.2001 |
250 |
80 |
|
2 |
1 |
John |
professor |
2281550 |
01.07.2001 |
400 |
150 |
|
3 |
2 |
Bill |
assistant |
NULL |
17.11.2002 |
240 |
80 |
|
4 |
2 |
Albert |
assistant |
NULL |
11.11.2001 |
260 |
100 |
SGROUP |
GrpNo |
DepNo |
Course |
Num |
Quantity |
Curator |
Rating |
|
1 |
1 |
1 |
101 |
33 |
4 |
20 |
|
2 |
1 |
1 |
102 |
35 |
4 |
22 |
|
3 |
3 |
2 |
205 |
20 |
1 |
15 |
|
4 |
3 |
3 |
305 |
25 |
NULL |
40 |
|
5 |
3 |
4 |
405 |
25 |
2 |
37 |
SUBJECT |
SbjNo |
Name |
|
1 |
pascal |
|
2 |
C |
|
3 |
OS |
|
4 |
inernet |
|
5 |
dbms |
ROOM |
RomNo |
Num |
Seate |
Floor |
Building |
|
1 |
101 |
20 |
1 |
5 |
|
2 |
316 |
150 |
3 |
5 |
|
3 |
201 |
150 |
2 |
2 |
|
4 |
202 |
30 |
2 |
5 |
LECTURE |
TchNo |
GrpNo |
SbjNo |
RomNo |
Type |
Day |
Week |
Lesson |
|
1 |
1 |
1 |
1 |
lecture |
mon |
1 |
1 |
|
1 |
2 |
2 |
1 |
lab |
mon |
1 |
1 |
|
2 |
3 |
3 |
1 |
lecture |
tue |
1 |
3 |
|
2 |
4 |
4 |
2 |
practice |
wed |
1 |
3 |
|
4 |
4 |
5 |
2 |
practice |
thu |
2 |
4 |
|
4 |
4 |
5 |
3 |
lab |
fri |
2 |
1 |
Insert in the FACULTY table information about your faculty/ Because of at that time information about teachers dies not exists, use NULL as a value of foreign key that references to the dean of the faculty.
Insert into DEPARTMENT table information about your department and all departments of teachers that teach you. Because of at that time information about teachers dies not exists, use NULL as a value of foreign key that references to the head of the department
Insert into TEACHER table information about all teaches that teach you, including dean of the faculty and head of the departments. . Teacher subordination is set in such a way:
- Dean of the faculty does not subordinate anybody
- Chief of the department subordinates to the dean
- Teachers that has lectures subordinates to the head of the department
- Teachers that has labs subordinates to the teacher that has lectures in the same subject.
Update FACULTY table by changing NULL in DeanFK column to the references to corresponding teacher
Update DEPARTMENT table by changing NULL in HeadFK column to the references to corresponding teacher.
Insert into SGROUP table information about your group.
Insert into SUBJECT table all disciplines that you study.
Insert into ROOM table information about all room where you have lectures.
Insert into LECTURE table information about all lectures that you have.