2013-03-13 66 views
1

是什么在MySQL DROP TABLE和--drop表之间的差异MySQL的下降语句 -

例如:如果我用我得到的错误 - 但在Magento的所有其他地方,他们正在使用 - 下降前。

--DROP TABLE IF EXISTS {$this->getTable('faq/dinkchika')}; 
CREATE TABLE IF NOT EXISTS {$this->getTable('faq/dinkchika')} (
    `faq_id` int(11) NOT NULL AUTO_INCREMENT, 
    `faq_question` varchar(255) DEFAULT NULL, 
    `faq_answer` varchar(255) DEFAULT NULL, 
    PRIMARY KEY (`faq_id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 


"); 

回答

2
use a white space after -- ,if you are not using whitespace after -- then it will not 
count as comment.after whitespace your query will look like this. 
-- DROP TABLE IF EXISTS {$this->getTable('faq/dinkchika')}; 
CREATE TABLE IF NOT EXISTS {$this->getTable('faq/dinkchika')} (
    `faq_id` int(11) NOT NULL AUTO_INCREMENT, 
    `faq_question` varchar(255) DEFAULT NULL, 
    `faq_answer` varchar(255) DEFAULT NULL, 
    PRIMARY KEY (`faq_id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 


"); 
Or you may use #(Hash) as well and 
Try this: Drop table IF EXISTS table_name; 
And then continue with creating the table, as it will be guaranteed to no longer exist. 
I hope it will help for you.. 
+0

之后使用空格。谢谢。有用 !!! – RIK 2013-03-13 06:04:53

+0

很棒...你的欢迎.. – Rahul 2013-03-13 12:57:55

4

以 - 开头并且之后有一个空格的行被视为注释直到行尾。它不会被执行。

你可以阅读更多关于MySQL注释语法在这里:http://dev.mysql.com/doc/refman/5.1/en/comments.html

+0

如果它是一个注释,那么为什么我会得到一个错误?我将该代码放入 RIK 2013-03-13 04:37:36

+1

您的--query不是注释,因为评论您必须在 - – Rahul 2013-03-13 05:58:38