2

I'm quite new on learning SQL and I seem to be running into an issue with the following code:

CREATE TABLE `read`
  (`order` NOT NULL UNIQUE AUTO_INCREMENT,
  `title` VARCHAR(50) NOT NULL,
  `url` VARCHAR(50) NOT NULL,
  PRIMARY KEY(`title`,`url`)
)DEFAULT CHARSET=UTF8;

It's returning the following error:

#1064 - 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 'NOT NULL UNIQUE AUTO_INCREMENT, title VARCHAR(50) NOT NULL, url VARCHAR(50' at line 2

5
  • I can't seem to answer my own question at this point but I figured it out. Adding INT after order solves it. Jul 8, 2013 at 3:33
  • 1
    Yes, that is correct. You hadn't defined a datatype for column order. And why have you accepted that answer? It doesn't explain what is wrong, it removes the UNIQUE constraint, it changes the PRIMARY KEY. Not very helpful. Do you know you can post an answer yourself? Jul 8, 2013 at 5:28
  • @ypercube Smart catch on the answer below. I ended up just using my own answer. However, I can't answer my own question as I don't have enough 'reputation' to do so. Jul 8, 2013 at 5:35
  • Oh yes, I think you need to have 15 reputation to do that or wait a few hours (or both, not sure.) Jul 8, 2013 at 5:40
  • @ypercube 10 rep points to answer or wait like 8 hours or something. I was able to get to 11 but now have to wait to accept my own answer. Thanks again. Jul 8, 2013 at 5:41

2 Answers 2

3

Try like below, it will help you...

CREATE TABLE `read`
  (`order` MEDIUMINT NOT NULL AUTO_INCREMENT,
  `title` VARCHAR(50) NOT NULL,
  `url` VARCHAR(50) NOT NULL,
  PRIMARY KEY(`order`)
)DEFAULT CHARSET=UTF8;
3
0
CREATE TABLE `read`
  (`order` INT NOT NULL UNIQUE AUTO_INCREMENT,
  `title` VARCHAR(255) NOT NULL,
  `url` VARCHAR(255) NOT NULL,
  PRIMARY KEY(`title`,`url`)
)DEFAULT CHARSET=UTF8;

I was missing INT after order

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.