Home > database >  Inserting a row in table that consist of only one auto increment PK column
Inserting a row in table that consist of only one auto increment PK column

Time:11-28

I have this table:

CREATE TABLE `VormerkListe` (
  `vormerkListeID` int NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`vormerkListeID`)
)

And I try to add a new column with this, found here:

INSERT INTO VormerkListe DEFAULT VALUES;

But I get this error:

INSERT INTO VormerkListe DEFAULT VALUES Error Code: 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 'DEFAULT VALUES' at line 1  0.031 sec

CodePudding user response:

You can insert a null value in the auto column. Something like this:

INSERT INTO VormerkListe (vormerkListeID) VALUES(null);

CodePudding user response:

You can also do this:

INSERT INTO VormerkListe () VALUES();

This looks funny, but I use it regularly. It means to use the default for every column in the table.

  • Related