Deleting Databases, Tables, and Indexes


Now that we know how to create databases, tables, and indexes, it is also useful to know how to delete these things. The keyword we need for this purpose is DROP .

We can delete an entire database and all its contents with the following statement (and we don't suggest that you type this at this stage!):

 
 drop database employee; 

We can add an optional IF EXISTS clause before the name of the database. If you look back at Listing 4.1, you can see that this is the version of the DROP DATABASE command we used there.

You can delete a single table with the DROP TABLE statement, for example,

 
 drop table assignment; 

The general form of the DROP TABLE statement is as follows :

 
 DROP [TEMPORARY] TABLE [IF EXISTS]  tbl_name  [,  tbl_name  ,...] 

You can specify the TEMPORARY keyword for dropping temporary tables. You can also drop multiple tables at once by listing a set of comma-separated names . The optional IF EXISTS clause works the same way as it does for DROP DATABASE .

You can delete an index with the DROP INDEX statement, for example,

 
 drop index part_name on employee; 

As you can see, you need to specify which table the index is on to delete the index.



MySQL Tutorial
MySQL Tutorial
ISBN: 0672325845
EAN: 2147483647
Year: 2003
Pages: 261

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net