tags:

views:

108

answers:

3

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;
+1  A: 

I've ALWAYS had issues with CREATE TABLE. Not sure why. Takes some trial-and-error.

Try this:

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;
Jonathan Sampson
Does MySQL allow something like int(11)?
Federico Ramponi
Yes. But I think it converts the declaration to an unsigned integer.
Jonathan Sampson
A: 

I had to delete the quote marks, as well as the default for the changed field, as well as the default charset. Hopefully that won't affect the data.

Elie
+2  A: 

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

Turnkey