MyISAM allows very convenient way to create serials. E.g. In the table primary key is id+seq(-uence)
id seq
1 1 insert into table(seq) values(1),(2),(3),(1),(2),(1),(1),(2);
1 2
1 3
2 1
2 2
3 1
4 1
4 2
So logic is when id remains the same untill appears duplicate key, in this case (MyISAM) will increment id.
But when I try use it in InnoDB - doesn't work. Is there a workaround (because I need transactions)?
Thanks.
May be better example from comments to Manual of MySQL Posted by [name withheld] on October 23 2003 8:41pm
create table location
(
id bigint not null auto_increment, -- "serial" per 4.1
longitude int,
latitude int,
place int,
primary key(id, longitude, latitude, place)
);
insert into location (longitude, latitude, place)
values (0,0,0), (1,1,1), (2,2,2);
select * from foo;
+----+-----------+----------+-------+
| id | longitude | latitude | place |
+----+-----------+----------+-------+
| 1 | 0 | 0 | 0 |
| 2 | 1 | 1 | 1 |
| 3 | 2 | 2 | 2 |
+----+-----------+----------+-------+
drop table location;
create table location
(
id bigint not null auto_increment, -- "serial" per 4.1
longitude int,
latitude int,
place int,
primary key(longitude, latitude, place, id)
);
insert into location (longitude, latitude, place)
values (0,0,0), (1,1,1), (2,2,2), (0,0,0);
select * from location order by id;
+----+-----------+----------+-------+
| id | longitude | latitude | place |
+----+-----------+----------+-------+
| 1 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 |
| 1 | 2 | 2 | 2 |
| 2 | 0 | 0 | 0 |
+----+-----------+----------+-------+