Previous Topic: Exercise 8-7Next Topic: Exercise 8-8


Removing Data from a Table

Use the DELETE statement to remove one or more rows from a database table.

How It's Done

One of the departments you entered previously, department 4040, shouldn't exist at all. Delete it by entering:

delete from department
     where dept_id = 4040;

This will delete only information on department 4040.

What message do you see?

You see a message stating that one row was deleted.

Display the Changes

Enter a SELECT statement to display the DEPARTMENT table to confirm the deletion.

The result looks like this:

 DEPT_ID  DEPT_HEAD_ID  DIV_CODE  DEPT_NAME

 -------  ------------  --------  ---------     1100          2246  D02       PURCHASING - USED CARS     1110          1765  D04       PURCHASING - NEW CARS     1120          2004  D06       PURCHASING - SERVICE     2200          2180  D02       SALES - USED CARS     2210          2010  D04       SALES - NEW CARS     3510          3082  D02       APPRAISAL - USED CARS     3520          3769  D04       APPRAISAL NEW CARS     3530          2209  D06       APPRAISAL - SERVICE     4200          1003  D04       LEASING - NEW CARS     4500          3222  D09       HUMAN RESOURCES     4600          2096  D06       MAINTENANCE     4900          2466  D09       MIS     5000          2466  D09       CORPORATE ACCOUNTING     5100          2598  D06       BILLING     5200          2894  D09       CORPORATE MARKETING     6000          1003  D09       LEGAL     6060        <null>  D09       Claims     6200          2461  D09       CORPORATE ADMINISTRATION  19 rows processed