Mysql -- inserting in table with only an auto incrementing column

only works if you're using an auto_increment primary key (PK) as every PK must have a unique, non null value.

drop table if exists A;
create table A
(
id int unsigned not null auto_increment primary key
)
engine=innodb;

insert into A (id) values (null),(null);

mysql> select * from A order by id;
+----+
| id |
+----+
|  1 |
|  2 |
+----+
2 rows in set (0.00 sec)

As soon as 'id' as the auto-increment enable (assuming ID is an integer), you can just do:

INSERT INTO A (id) values (null)

and 'id' will keep incrementing each time.

Tags:

Mysql