Deleting Databases and Tables
It is also simple to delete tables and
databases using GUI tools or SQL. In the case of a GUI, you
will simply select a table or database from your main menu
and delete it as you would a file in a file system manager.
In SQL, you would simply use the DELETE or DROP commands
depending on if you were deleting a whole database or just a table in a
single database.
In the case of deleting a whole database, you
will use the DELETE command as follows:
DELETE DATABASE DATABASE_NAME;
The following example would delete the
database MY_COMPANY:
DELETE DATABASE MY_COMPANY;
In the case of a table, you use the DROP
command:
DROP TABLE TABLE_NAME;
such as:
DROP TABLE EMPLOYEES;
Essentially when you use delete and drop, you
are modifying the database management system's data dictionary.
It shouldn't have to be said, but I will say it...BE CAREFUL WHEN DELETING
OR DROPPING!
Altering a Table
Finally, you should know that it is possible to "alter"
a table after it has been created using either a standard GUI tool or
by using the ALTER SQL command as follows:
ALTER TABLE TABLE_NAME
DROP COLUMN_NAME, COLUMN_NAME
ADD COLUMN_NAME DATA_TYPE, COLUMN_NAME DATA_TYPE
RENAME COLUMN_NAME NEW NAME
MODIFY COLUMN_NAME DATA_TYPE;
such as the following case in which
we alter the table named EMPLOYEES by dropping the E_GENDER
Column and adding an E_ZIP column which will accept INTEGERS
and which must be filled in for every new employee added to the table,
and the E_MIDDLE_INIT column which will accept a single
character as a value.
ALTER TABLE EMPLOYEES
DROP E_GENDER
ADD E_ZIP INTEGER NOT NULL,
E_MIDDLE_INIT CHAR (1);