Click to See Complete Forum and Search --> : deleting an entire table in mysql


Warhead
04-03-2004, 04:54 AM
how do i delete an entire table in mysql?
I know that to delete all rows of the table i can simply use:
mysql> DELETE FROM table;

but i actually jsut wanna delete the table itself.

cheers

AdamGundry
04-03-2004, 06:30 AM
You need to use DROP TABLE (http://www.mysql.com/doc/en/DROP_TABLE.html).

Adam

buntine
04-03-2004, 06:34 AM
To remove an entire table, you use the SQL DROP TABLE query. The basic syntax is below.

DROP TABLE tableName;


Also, to destroy an entire dataabse, SQL provides the DROP DATEBASE keyword. Be careful, it doesnt ask if your sure 5 times, it just deletes the whole database, forever..

DROP DATEBASE DBname;


Finally, you can first run a conditional statement which will determine whether the given table/database exists before it removes it.

DROP DATABASE IF EXISTS DBname;
DROP DATABASE IF NOT EXISTS DBname;
DROP TABLE IF EXISTS tableName;
DROP TABLE IF NOT EXISTS tableName;


EDIT: Adam beat me.. :eek:

Regards,
Andrew Buntine.

Warhead
04-03-2004, 12:50 PM
Cheers guys__knew i was jsut being slow!!