开发者

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

开发者 https://www.devze.com 2023-03-06 23:56 出处:网络
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());

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开发者_Python百科 specifying the dbName.tableName is invalid?


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


You should use backticks instead of double quotes like this:

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


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`
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号