1
drop table if exists t1;
2
drop table if exists t2;
4
create TEMPORARY table t1 (a int not null auto_increment,b int, primary key (a)) engine=myisam auto_increment=3;
5
insert into t1 values (1,1),(NULL,3),(NULL,4);
6
delete from t1 where a=4;
7
insert into t1 values (NULL,5),(NULL,6);
14
delete from t1 where a=6;
15
replace t1 values (3,1);
16
ALTER TABLE t1 add c int;
17
replace t1 values (3,3,3);
18
insert into t1 values (NULL,7,7);
19
update t1 set a=8,b=b+1,c=c+1 where a=7;
20
insert into t1 values (NULL,9,9);
30
skey int NOT NULL auto_increment PRIMARY KEY,
33
insert into t1 values (NULL, "hello");
34
insert into t1 values (NULL, "hey");
39
select _rowid,t1._rowid,skey,sval from t1;
40
_rowid _rowid skey sval
44
create table t1 (a int not null primary key auto_increment);
45
insert into t1 values (0);
51
Table Op Msg_type Msg_text
52
test.t1 check status OK
54
create table t1 (a int not null auto_increment primary key);
55
insert into t1 values (NULL);
56
insert into t1 values (-1);
57
select last_insert_id();
60
insert into t1 values (NULL);
67
create temporary table t1 (a int not null auto_increment primary key) /*!40102 engine=heap */;
68
insert into t1 values (NULL);
69
insert into t1 values (-1);
70
select last_insert_id();
73
insert into t1 values (NULL);
80
create table t1 (i int not null auto_increment, key (i));
81
insert into t1 set i = 254;
82
insert into t1 set i = null;
83
select last_insert_id();
86
insert into t1 set i = null;
87
select last_insert_id();
91
create table t1 (i int not null auto_increment primary key, b int, unique (b));
92
insert into t1 values (NULL, 10);
93
select last_insert_id();
96
insert into t1 values (NULL, 15);
97
select last_insert_id();
100
insert into t1 values (NULL, 10);
101
ERROR 23000: Duplicate entry '10' for key 'b'
102
select last_insert_id();
106
create table t1(a int auto_increment,b int null,primary key(a));
107
insert into t1(a,b)values(NULL,1);
108
insert into t1(a,b)values(200,2);
109
insert into t1(a,b)values(0,3);
110
insert into t1(b)values(4);
111
insert into t1(b)values(5);
112
insert into t1(b)values(6);
113
insert into t1(b)values(7);
114
select * from t1 order by b;
123
alter table t1 modify b int;
124
select * from t1 order by b;
133
create table t2 (a int);
134
insert t2 values (1),(2);
135
alter table t2 add b int auto_increment primary key;
141
delete from t1 where a=0;
142
update t1 set a=0 where b=5;
143
select * from t1 order by b;
151
delete from t1 where a=0;
152
update t1 set a=NULL where b=6;
153
ERROR 23000: Column 'a' cannot be null
154
update t1 set a=300 where b=7;
155
insert into t1(a,b)values(NULL,8);
156
insert into t1(a,b)values(400,9);
157
insert into t1(a,b)values(0,10);
158
insert into t1(b)values(11);
159
insert into t1(b)values(12);
160
insert into t1(b)values(13);
161
insert into t1(b)values(14);
162
select * from t1 order by b;
176
delete from t1 where a=0;
177
update t1 set a=0 where b=12;
178
select * from t1 order by b;
191
delete from t1 where a=0;
192
update t1 set a=NULL where b=13;
193
ERROR 23000: Column 'a' cannot be null
194
update t1 set a=500 where b=14;
195
select * from t1 order by b;
208
create table t1 (a bigint);
209
insert into t1 values (1), (2), (3), (NULL), (NULL);
210
alter table t1 modify a bigint not null auto_increment primary key;
219
create table t1 (a bigint);
220
insert into t1 values (1), (2), (3), (0), (0);
221
alter table t1 modify a bigint not null auto_increment primary key;
222
ERROR 23000: ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry '0' for key 'PRIMARY'
231
create table t1 (a bigint);
232
insert into t1 values (0), (1), (2), (3);
233
alter table t1 modify a bigint not null auto_increment primary key;
241
create table t1 (a int auto_increment primary key , b int null);
242
insert into t1 values (0,1),(1,2),(2,3);
248
alter table t1 modify b varchar(255);
249
insert into t1 values (0,4);
250
ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
257
CREATE TABLE t1 ( a INT AUTO_INCREMENT, b BLOB, PRIMARY KEY (a,b(10)));
258
INSERT INTO t1 (b) VALUES ('aaaa');
260
Table Op Msg_type Msg_text
261
test.t1 check status OK
262
INSERT INTO t1 (b) VALUES ('');
264
Table Op Msg_type Msg_text
265
test.t1 check status OK
266
INSERT INTO t1 (b) VALUES ('bbbb');
268
Table Op Msg_type Msg_text
269
test.t1 check status OK
270
DROP TABLE IF EXISTS t1;
272
t1_name VARCHAR(255) DEFAULT NULL,
273
t1_id INT not null AUTO_INCREMENT,
276
) AUTO_INCREMENT = 1000;
277
INSERT INTO t1 (t1_name) VALUES('MySQL');
278
INSERT INTO t1 (t1_name) VALUES('MySQL');
279
INSERT INTO t1 (t1_name) VALUES('MySQL');
285
SHOW CREATE TABLE `t1`;
287
t1 CREATE TABLE `t1` (
288
`t1_name` varchar(255) DEFAULT NULL,
289
`t1_id` int NOT NULL AUTO_INCREMENT,
290
PRIMARY KEY (`t1_id`),
291
KEY `t1_name` (`t1_name`)
294
create table t1(a int not null auto_increment primary key);
295
create table t2(a int not null auto_increment primary key, t1a int);
296
insert into t1 values(NULL);
297
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID());
298
insert into t1 values (NULL);
299
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()),
300
(NULL, LAST_INSERT_ID());
301
insert into t1 values (NULL);
302
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()),
303
(NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID());
317
CREATE TABLE t1 ( `a` int NOT NULL auto_increment, `b` int default NULL,PRIMARY KEY (`a`),UNIQUE KEY `b` (`b`));
318
insert into t1 (b) values (1);
319
replace into t1 (b) values (2), (1), (3);
326
insert into t1 (b) values (1);
327
replace into t1 (b) values (2);
328
replace into t1 (b) values (1);
329
replace into t1 (b) values (3);
336
create table t1 (rowid int not null auto_increment, val int not null,primary
337
key (rowid), unique(val));
338
replace into t1 (val) values ('1'),('2');
339
replace into t1 (val) values ('1'),('2');
340
insert into t1 (val) values ('1'),('2');
341
ERROR 23000: Duplicate entry '1' for key 'val'
347
CREATE TABLE t1 (t1 INT PRIMARY KEY, t2 INT);
348
INSERT INTO t1 VALUES(0, 0);
349
INSERT INTO t1 VALUES(1, 1);
350
ALTER TABLE t1 CHANGE t1 t1 INT auto_increment;
351
INSERT INTO t1 VALUES(0,0);
352
ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
354
create table t1 (a int primary key auto_increment, b int, c int, d timestamp default current_timestamp, unique(b),unique(c));
355
insert into t1 values(null,1,1,now());
356
insert into t1 values(null,0,0,null);
357
replace into t1 values(null,1,0,null);
358
select last_insert_id();