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

closed as off-topic by StanleyJohns, Nick Chammas, dezso, RolandoMySQLDBA, Paul White Jul 8 '13 at 13:40

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – StanleyJohns, Nick Chammas, dezso, RolandoMySQLDBA, Paul White
If this question can be reworded to fit the rules in the help center, please edit the question.

  • I can't seem to answer my own question at this point but I figured it out. Adding INT after order solves it. – Chris Burton Jul 8 '13 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? – ypercubeᵀᴹ Jul 8 '13 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. – Chris Burton Jul 8 '13 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.) – ypercubeᵀᴹ Jul 8 '13 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. – Chris Burton Jul 8 '13 at 5:41
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;
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

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