2013-03-13 97 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