分类: Mysql/postgreSQL
2013-11-13 10:19:38
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
1
CREATE TABLE Tickets64 (
2
id bigint(20) unsigned NOT NULL auto_increment,
3
stub char(1) NOT NULL default '',
4
PRIMARY KEY (id),
5
UNIQUE KEY stub (stub)
6
) ENGINE=MyISAM
当我们插入记录后,执行SELECT * from Tickets64,查询结果就是这样的:
1
+-------------------+------+
2
| id | stub |
3
+-------------------+------+
4
| 72157623227190423 | a |
5
+-------------------+------+
在我们的应用端需要做下面这两个操作,在一个事务会话里提交:
1
REPLACE INTO Tickets64 (stub) VALUES ('a');
2
SELECT LAST_INSERT_ID();
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
1
TicketServer1:
2
auto-increment-increment = 2
3
auto-increment-offset = 1
4
5
TicketServer2:
6
auto-increment-increment = 2
7
auto-increment-offset = 2
|