Page 1 of 1

Checking table existence before DROPping it

Posted: Sun Jul 25, 2004 9:18 am
by mjseaden
Dear All,

How do I check for the existence of a table in a MySQL database, and if so, delete it?

Many thanks

Mark

Posted: Sun Jul 25, 2004 10:02 am
by kettle_drum
You can use mysql_list_tables() and then see if its in the results, if it is then delete it:

Code: Select all

DROP TABLE `the_table_i_want_to_delete`

Posted: Sun Jul 25, 2004 10:04 am
by mjseaden
Hi Kettle,

Is there any form of 'IF EXIST()' check I can use to determine a table's existence? Otherwise will it not produce an error?

Many thanks

Mark

Posted: Sun Jul 25, 2004 11:46 am
by feyd
DROP TABLE Syntax wrote:DROP [TEMPORARY] TABLE [IF EXISTS]
    tbl_name [, tbl_name] ...
    [RESTRICT | CASCADE]