Author Topic: mysql  (Read 1610 times)

0 Members and 1 Guest are viewing this topic.

Offline broodjehamburger

  • Posts: 64
    • View Profile
mysql
« on: February 04, 2014, 12:16:47 pm »
Hey guys,

I'm fooling around with mysql but can't figure out how to set the table id in a way that it's automatically +1'ed
for example i want to add an employee with this command:

insert into werknemers values(null, 'Jan', 'de Boer', '123', '440');

Now the 'null' should make the +1 happen automatically but it gives this error:
"#1048 - Column 'id' cannot be null"

the table ID is the primary key. Does it has to do something with that? I already tried changing the standard value to null but every time i save it it still says "as indicated" which is 0.
anyway i hope someone here can help me out :)


Offline [MAF]Cromiell

Re: mysql
« Reply #1 on: February 04, 2014, 01:24:33 pm »
If id is auto_increment you can skip the id while inserting beacuse it's +1 each entry.

Try this:

INSERT INTO werknemers (column1, column2, column3, column4) VALUES( 'Jan', 'de Boer', '123', '440');

basically just skip the id because it's not something you can touch this way
« Last Edit: February 04, 2014, 01:55:07 pm by [MAF]Cromiell »

Offline broodjehamburger

  • Posts: 64
    • View Profile
Re: mysql
« Reply #2 on: February 04, 2014, 02:31:36 pm »
Ah thanks man, it wasn't an auto_increment so i had to delete the column and alter the shit out it but everything worked out fine :)