Removing a Table (DROP TABLE)

Removing a Table (DROP TABLE)
Over time, the structure of a database will change; new tables will be created and some
tables will no longer be needed. We can remove a redundant table from the database using
the DROP TABLE statement, which has the format:
DROP TABLE TableName [RESTRICT | CASCADE]
For example, to remove the PropertyForRent table we use the command:
DROP TABLE PropertyForRent;
Note, however, that this command removes not only the named table, but also all the rows
within it. To simply remove the rows from the table but retain the table structure, use the
DELETE statement instead (see Section 5.3.10). The DROP TABLE statement allows you
to specify whether the DROP action is to be cascaded or not:
n RESTRICT The DROP operation is rejected if there are any other objects that depend
for their existence upon the continued existence of the table to be dropped.
n CASCADE The DROP operation proceeds and SQL automatically drops all dependent
objects (and objects dependent on these objects).
The total effect of a DROP TABLE with CASCADE can be very extensive and should be
carried out only with extreme caution. One common use of DROP TABLE is to correct
mistakes made when creating a table. If a table is created with an incorrect structure,
DROP TABLE can be used to delete the newly created table and start again.
Removing a Table (DROP TABLE) Removing a Table (DROP TABLE) Reviewed by Shopping Sale on 11:58 Rating: 5

No comments:

Powered by Blogger.