RelationalDBDesign RelationalDBDesign


SQL*Loader   «Prev  Next»

Report and remove an unused column - Exercise

Dropping columns


Objective: Write SQL commands to drop columns.

Background/overview

You are going to write some SQL commands to drop columns or set columns to unused status. You will also answer a question about these commands.

Download files

None.

Instructions

Answer the questions below:
  1. Here is a query and the resulting report. Using the information shown here, write a set of SQL commands that drop all the unused columns from their corresponding tables.
    <pre>
    SQL> select * from DBA_UNUSED_COL_TABS;
    OWNER TABLE_NAME COUNT
    ---------- ------------------------------
    ---------
    PETSTORE PRODUCT 1
    EPET1 CUSTOMER_ACCOUNT 2
    WEBPETS PRODUCT_INVENTORY 3
    

  2. The PRODUCT_INVENTORY table is in heavy use during the day, but you want to drop the CREATED_TIME column from the table. How can you drop the column?
  3. Write the SQL commands you can use.

Submitting your exercise

Type your answer into the text box and click the Submit button to submit your answer. Remember that you must submit all your responses to this exercise at once.
Answer to question 1:

ALTER TABLE PETSTORE.PRODUCT DROP UNUSED COLUMNS;
ALTER TABLE EPET1.CUSTOMER_ACCOUNT DROP UNUSED COLUMNS;
ALTER TABLE WEBPETS.PRODUCT_INVENTORY DROP UNUSED COLUMNS;

Answer to question 2:
First, mark the column as unused during the day. Second, at night or over the weekend, drop the column.

Answer to question 3:
ALTER TABLE PRODUCT_INVENTORY SET UNUSED COLUMN CREATED_TIME;
ALTER TABLE PRODUCT_INVENTORY DROP UNUSED COLUMNS;