H. Ferrence
H. Ferrence

Reputation: 8106

Can you DROP TABLE IF EXISTS by specifying database name with table?

I am trying to drop a table in a database with the following query statement:

mysql_query('DROP TABLE IF EXISTS "dbName.tableName"') or die(mysql_error());

But I keep getting an error. Does anyone know if specifying the dbName.tableName is invalid?

Upvotes: 8

Views: 36591

Answers (3)

John Cartwright
John Cartwright

Reputation: 5084

You can't use double quotes to quote db/table names, instead you either leave them unquoted or use backticks. But to answer your question, yes it is perfectly valid to specify the database name.

DROP TABLE `dbName`.`tableName`

Upvotes: 3

Kris
Kris

Reputation: 2128

You should use backticks instead of double quotes like this:

mysql_query('DROP TABLE IF EXISTS `dbName`.`tableName`');

Upvotes: 6

Emmerman
Emmerman

Reputation: 2343

mysql_query('DROP TABLE IF EXISTS `dbName`.`tableName`') or die(mysql_error());

Upvotes: 21

Related Questions