【发布时间】:2011-09-17 05:03:07
【问题描述】:
MyISAM 允许以非常方便的方式创建连续剧。 例如。表中主键为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
所以逻辑是当 id 保持不变直到出现重复键时,在这种情况下(MyISAM)将增加 id。
但是当我尝试在 InnoDB 中使用它时 - 不起作用。是否有解决方法(因为我需要交易)?
谢谢。
可能是从 cmets 到 Manual of MySQL 的更好示例 由 [name 保留] 于 2003 年 10 月 23 日晚上 8:41 发布
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 |
+----+-----------+----------+-------+
【问题讨论】:
-
我假设您在谈论 MyISAM 在主键是复合时的功能。如果是这样的话,不——这样的功能不适用于 InnoDB。解决方法 - 放弃 auto_increment,编写自己的程序来计算密钥 - 基本上,很麻烦。
标签: mysql innodb myisam auto-increment