1

mysql中的drop table和--drop table有什么区别

例如:如果我使用 - 但在 Magento 的所有其他地方他们正在使用 - 在 drop 之前,我会收到错误。

--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;


");
4

2 回答 2

4

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

您可以在此处阅读有关 Mysql 注释语法的更多信息:http: //dev.mysql.com/doc/refman/5.1/en/comments.html

于 2013-03-13T04:09:22.130 回答
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..
于 2013-03-13T05:56:03.790 回答