Mysql – Create Table Syntax Error

databasemysql

I received a MySQL data dump and am trying to insert the data into a set of temporary tables. The creation statement for the first table is shown below. When I run this I receive the error: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''temp_books'( 'ID'int( 11 ) NOT NULL AUTO_INCREMENT, 'start'varchar( 20 ) ' at line 1". I've checked the documentation for MySQL syntax, and I don't see that the problem is.

CREATE TABLE 'temp_books' (
  'ID' int(11) NOT NULL AUTO_INCREMENT,
  'start' varchar(20) NOT NULL,
  'customer_id' int(11) NOT NULL DEFAULT '0',
  'total_num' int(11) NOT NULL,
  'amount' double(5,2) NOT NULL DEFAULT '0.00',
  'changed' timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY ('ID'),
  UNIQUE KEY 'start' ('start')
) ENGINE=MyISAM AUTO_INCREMENT=4853 DEFAULT CHARSET=latin1;

Best Solution

You shouldn't put single-quotes on your identifiers. If you're going to quote them use the "back tick" character (“`”). You can also use double-quotes but you have to specify that mode:

SET sql_mode='ANSI_QUOTES';

http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

Related Question