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
show table status like "t1";
16
Session Schema Name Type Engine Version Rows Avg_row_length Table_size Auto_increment
17
# test t1 TEMPORARY MyISAM # # # # #
18
replace t1 values (3,1);
19
ALTER TABLE t1 add c int;
20
replace t1 values (3,3,3);
21
insert into t1 values (NULL,7,7);
22
update t1 set a=8,b=b+1,c=c+1 where a=7;
23
insert into t1 values (NULL,9,9);
33
skey int NOT NULL auto_increment PRIMARY KEY,
36
insert into t1 values (NULL, "hello");
37
insert into t1 values (NULL, "hey");
42
select _rowid,t1._rowid,skey,sval from t1;
43
_rowid _rowid skey sval
47
create table t1 (a int not null primary key auto_increment);
48
insert into t1 values (0);
54
Table Op Msg_type Msg_text
55
test.t1 check status OK
57
create table t1 (a int not null auto_increment primary key);
58
insert into t1 values (NULL);
59
insert into t1 values (-1);
60
select last_insert_id();
63
insert into t1 values (NULL);
70
create temporary table t1 (a int not null auto_increment primary key) /*!40102 engine=MEMORY */;
71
insert into t1 values (NULL);
72
insert into t1 values (-1);
73
select last_insert_id();
76
insert into t1 values (NULL);
83
create table t1 (i int not null auto_increment, key (i));
84
insert into t1 set i = 254;
85
insert into t1 set i = null;
86
select last_insert_id();
89
insert into t1 set i = null;
90
select last_insert_id();
94
create table t1 (i int not null auto_increment primary key, b int, unique (b));
95
insert into t1 values (NULL, 10);
96
select last_insert_id();
99
insert into t1 values (NULL, 15);
100
select last_insert_id();
103
insert into t1 values (NULL, 10);
104
ERROR 23000: Duplicate entry '10' for key 'b'
105
select last_insert_id();
109
create table t1(a int auto_increment,b int null,primary key(a));
110
insert into t1(a,b)values(NULL,1);
111
insert into t1(a,b)values(200,2);
112
insert into t1(a,b)values(0,3);
113
insert into t1(b)values(4);
114
insert into t1(b)values(5);
115
insert into t1(b)values(6);
116
insert into t1(b)values(7);
117
select * from t1 order by b;
126
alter table t1 modify b int;
127
select * from t1 order by b;
136
create table t2 (a int);
137
insert t2 values (1),(2);
138
alter table t2 add b int auto_increment primary key;
144
delete from t1 where a=0;
145
update t1 set a=0 where b=5;
146
select * from t1 order by b;
154
delete from t1 where a=0;
155
update t1 set a=NULL where b=6;
156
ERROR 23000: Column 'a' cannot be null
157
update t1 set a=300 where b=7;
158
insert into t1(a,b)values(NULL,8);
159
insert into t1(a,b)values(400,9);
160
insert into t1(a,b)values(0,10);
161
insert into t1(b)values(11);
162
insert into t1(b)values(12);
163
insert into t1(b)values(13);
164
insert into t1(b)values(14);
165
select * from t1 order by b;
179
delete from t1 where a=0;
180
update t1 set a=0 where b=12;
181
select * from t1 order by b;
194
delete from t1 where a=0;
195
update t1 set a=NULL where b=13;
196
ERROR 23000: Column 'a' cannot be null
197
update t1 set a=500 where b=14;
198
select * from t1 order by b;
211
create table t1 (a bigint);
212
insert into t1 values (1), (2), (3), (NULL), (NULL);
213
alter table t1 modify a bigint not null auto_increment primary key;
222
create table t1 (a bigint);
223
insert into t1 values (1), (2), (3), (0), (0);
224
alter table t1 modify a bigint not null auto_increment primary key;
225
ERROR 23000: ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry '0' for key 'PRIMARY'
234
create table t1 (a bigint);
235
insert into t1 values (0), (1), (2), (3);
236
alter table t1 modify a bigint not null auto_increment primary key;
244
create table t1 (a int auto_increment primary key , b int null);
245
insert into t1 values (0,1),(1,2),(2,3);
251
alter table t1 modify b varchar(255);
252
insert into t1 values (0,4);
253
ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
260
CREATE TABLE t1 ( a INT AUTO_INCREMENT, b BLOB, PRIMARY KEY (a,b(10)));
261
INSERT INTO t1 (b) VALUES ('aaaa');
263
Table Op Msg_type Msg_text
264
test.t1 check status OK
265
INSERT INTO t1 (b) VALUES ('');
267
Table Op Msg_type Msg_text
268
test.t1 check status OK
269
INSERT INTO t1 (b) VALUES ('bbbb');
271
Table Op Msg_type Msg_text
272
test.t1 check status OK
273
DROP TABLE IF EXISTS t1;
275
t1_name VARCHAR(255) DEFAULT NULL,
276
t1_id INT not null AUTO_INCREMENT,
279
) AUTO_INCREMENT = 1000;
280
INSERT INTO t1 (t1_name) VALUES('MySQL');
281
INSERT INTO t1 (t1_name) VALUES('MySQL');
282
INSERT INTO t1 (t1_name) VALUES('MySQL');
288
SHOW CREATE TABLE `t1`;
290
t1 CREATE TABLE `t1` (
291
`t1_name` varchar(255) DEFAULT NULL,
292
`t1_id` int NOT NULL AUTO_INCREMENT,
293
PRIMARY KEY (`t1_id`),
294
KEY `t1_name` (`t1_name`)
297
create table t1(a int not null auto_increment primary key);
298
create table t2(a int not null auto_increment primary key, t1a int);
299
insert into t1 values(NULL);
300
insert into t2 values (NULL, LAST_INSERT_ID()), (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());
304
insert into t1 values (NULL);
305
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()),
306
(NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID());
320
CREATE TABLE t1 ( `a` int NOT NULL auto_increment, `b` int default NULL,PRIMARY KEY (`a`),UNIQUE KEY `b` (`b`));
321
insert into t1 (b) values (1);
322
replace into t1 (b) values (2), (1), (3);
329
insert into t1 (b) values (1);
330
replace into t1 (b) values (2);
331
replace into t1 (b) values (1);
332
replace into t1 (b) values (3);
339
create table t1 (rowid int not null auto_increment, val int not null,primary
340
key (rowid), unique(val));
341
replace into t1 (val) values ('1'),('2');
342
replace into t1 (val) values ('1'),('2');
343
insert into t1 (val) values ('1'),('2');
344
ERROR 23000: Duplicate entry '1' for key 'val'
350
CREATE TABLE t1 (t1 INT PRIMARY KEY, t2 INT);
351
INSERT INTO t1 VALUES(0, 0);
352
INSERT INTO t1 VALUES(1, 1);
353
ALTER TABLE t1 CHANGE t1 t1 INT auto_increment;
354
INSERT INTO t1 VALUES(0,0);
355
ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
357
create table t1 (a int primary key auto_increment, b int, c int, d timestamp default current_timestamp, unique(b),unique(c));
358
insert into t1 values(null,1,1,now());
359
insert into t1 values(null,0,0,null);
360
replace into t1 values(null,1,0,null);
361
select last_insert_id();