0

I'm trying to make simple database since yesterday with primary id key with AUTO_INCREMENT option but keep getting this error:

Executing:
CREATE TABLE `spring`.`samochod` (
`idsamochod` INT NOT NULL DEFAULT AUTO_INCREMENT,
PRIMARY KEY (`idsamochod`));

Operation failed: There was an error while applying the SQL script to the database.
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 'AUTO_INCREMENT,
PRIMARY KEY (`idsamochod`))' at line 2
SQL Statement:
CREATE TABLE `spring`.`samochod` (
  `idsamochod` INT NOT NULL DEFAULT AUTO_INCREMENT,
  PRIMARY KEY (`idsamochod`))

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 'AUTO_INCREMENT,
PRIMARY KEY (`idsamochod`))' at line 2

SQL Statement:

CREATE TABLE `spring`.`samochod` (
  `idsamochod` INT NOT NULL DEFAULT AUTO_INCREMENT,
  PRIMARY KEY (`idsamochod`))

I am getting this error even for normal integer columns. I have read many articles before and as far as I understand it should work this way without any problems.

Could anyone tell me what I'm doing wrong?

2
  • Why did you tag mysql and sql-server, when your question is about MySQL? Commented Jun 11, 2016 at 9:14
  • Why do you think that this might be valid syntax Commented Jun 11, 2016 at 9:17

1 Answer 1

3

The problem is not the AUTO_INCREMENT but the DEFAULT before it. No value has been specified for DEFAULT. Just remove the DEFAULT keyword which is not needed here.

See also the CREATE TABLE syntax in the MySQL documentation, specifically:

column_definition:
    data_type [NOT NULL | NULL] [DEFAULT default_value]
      [AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY]
      [COMMENT 'string']
      [COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}]
      [STORAGE {DISK|MEMORY|DEFAULT}]
      [reference_definition]
Sign up to request clarification or add additional context in comments.

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.