1

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;

4 Answers 4

4

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

Sign up to request clarification or add additional context in comments.

Comments

2

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;

2 Comments

Does MySQL allow something like int(11)?
Yes. But I think it converts the declaration to an unsigned integer.
0

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.

Comments

0

Here's another way of writing it that might work for some: (left away most of the columns for brevity)

create table temp_books
(
id int not null,
start varchar(255) null,
constraint six_cb_datasource_pk
    primary key (id)
);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.