37
37
# Test auto_increment on sub key
39
create table t1 (a char(10) not null, b int not null auto_increment, primary key(a,b));
40
insert into t1 values ("a",1),("b",2),("a",2),("c",1);
41
insert into t1 values ("a",NULL),("b",NULL),("c",NULL),("e",NULL);
42
insert into t1 (a) values ("a"),("b"),("c"),("d");
43
insert into t1 (a) values ('k'),('d');
44
insert into t1 (a) values ("a");
45
insert into t1 values ("d",last_insert_id());
49
create table t1 (ordid int(8) not null auto_increment, ord varchar(50) not null, primary key (ordid), index(ord,ordid));
50
insert into t1 (ordid,ord) values (NULL,'sdj'),(NULL,'sdj');
54
create table t1 (ordid int(8) not null auto_increment, ord varchar(50) not null, primary key (ord,ordid));
55
insert into t1 values (NULL,'sdj'),(NULL,'sdj'),(NULL,"abc"),(NULL,'abc'),(NULL,'zzz'),(NULL,'sdj'),(NULL,'abc');
59
create table t1 (sid char(5), id int(2) NOT NULL auto_increment, key(sid, id));
60
create table t2 (sid char(20), id int(2));
61
insert into t2 values ('skr',NULL),('skr',NULL),('test',NULL);
62
insert into t1 select * from t2;
39
#Drizzle does not support auto_increment on sub key.
40
#create table t1 (a char(10) not null, b int not null auto_increment, primary key(b));
41
#insert into t1 values ("a",1),("b",2),("a",2),("c",1);
42
#insert into t1 values ("a",NULL),("b",NULL),("c",NULL),("e",NULL);
43
#insert into t1 (a) values ("a"),("b"),("c"),("d");
44
#insert into t1 (a) values ('k'),('d');
45
#insert into t1 (a) values ("a");
46
#insert into t1 values ("d",last_insert_id());
50
#create table t1 (ordid int(8) not null auto_increment, ord varchar(50) not null, primary key (ordid), index(ord,ordid));
51
#insert into t1 (ordid,ord) values (NULL,'sdj'),(NULL,'sdj');
55
#create table t1 (ordid int(8) not null auto_increment, ord varchar(50) not null, primary key (ord,ordid));
56
#insert into t1 values (NULL,'sdj'),(NULL,'sdj'),(NULL,"abc"),(NULL,'abc'),(NULL,'zzz'),(NULL,'sdj'),(NULL,'abc');
60
#create table t1 (sid char(5), id int(2) NOT NULL auto_increment, key(sid, id));
61
#create table t2 (sid char(20), id int(2));
62
#insert into t2 values ('skr',NULL),('skr',NULL),('test',NULL);
63
#insert into t1 select * from t2;
67
68
# Test of auto_increment columns when they are set to 0
97
98
# last_insert_id() madness
99
create table t1 (i int not null auto_increment primary key);
100
insert into t1 set i = 254;
101
insert into t1 set i = null;
102
select last_insert_id();
103
explain extended select last_insert_id();
105
insert into t1 set i = 254;
106
select last_insert_id();
108
insert into t1 set i = null;
109
select last_insert_id();
99
# Bug 314554 - Autoincrement succeeds where it should have failed
101
#create table t1 (i int not null auto_increment primary key);
102
#insert into t1 set i = 254;
103
#insert into t1 set i = null;
104
#select last_insert_id();
105
#explain extended select last_insert_id();
106
#--error ER_DUP_ENTRY
107
#insert into t1 set i = 254;
108
#select last_insert_id();
109
#--error ER_DUP_ENTRY
110
#insert into t1 set i = null;
111
#select last_insert_id();
112
114
create table t1 (i int not null auto_increment, key (i));
113
115
insert into t1 set i = 254;
190
195
# We still should be able to preserve zero in NO_AUTO_VALUE_ON_ZERO mode
191
create table t1 (a bigint);
192
insert into t1 values (0), (1), (2), (3);
193
set sql_mode=NO_AUTO_VALUE_ON_ZERO;
194
alter table t1 modify a bigint not null auto_increment primary key;
196
#create table t1 (a bigint);
197
#insert into t1 values (0), (1), (2), (3);
199
#sql_mode not supported
200
#set sql_mode=NO_AUTO_VALUE_ON_ZERO;
202
# Bug314567 - ALTER TABLE causes auto_increment resequencing,
203
# resulting in duplicate entry since sql_mode=NO_AUTO_VALUE_ON_ZERO
206
#alter table t1 modify a bigint not null auto_increment primary key;
199
211
# It also sensible to preserve zeroes if we are converting auto_increment
200
212
# column to auto_increment column (or not touching it at all, which is more
201
213
# common case probably)
202
214
create table t1 (a int auto_increment primary key , b int null);
203
set sql_mode=NO_AUTO_VALUE_ON_ZERO;
204
insert into t1 values (0,1),(1,2),(2,3);
215
#sql_mode is not supported.
216
#set sql_mode=NO_AUTO_VALUE_ON_ZERO;
217
#insert into t1 values (0,1),(1,2),(2,3);
207
220
alter table t1 modify b varchar(255);
208
221
insert into t1 values (0,4);
209
222
select * from t1;
288
301
# Test that update changes internal auto-increment value
291
create table t1 (a int not null auto_increment primary key, val int);
292
insert into t1 (val) values (1);
293
update t1 set a=2 where a=1;
294
insert into t1 (val) values (1);
304
#create table t1 (a int not null auto_increment primary key, val int);
305
#insert into t1 (val) values (1);
306
#update t1 set a=2 where a=1;
307
#insert into t1 (val) values (1);
299
312
# Test key duplications with auto-increment in ALTER TABLE
302
CREATE TABLE t1 (t1 INT(10) PRIMARY KEY, t2 INT(10));
315
#changed syntax of int(11) to int.
316
CREATE TABLE t1 (t1 INT PRIMARY KEY, t2 INT);
303
317
INSERT INTO t1 VALUES(0, 0);
304
318
INSERT INTO t1 VALUES(1, 1);
305
319
--error ER_DUP_ENTRY
306
ALTER TABLE t1 CHANGE t1 t1 INT(10) auto_increment;
320
ALTER TABLE t1 CHANGE t1 t1 INT auto_increment;
309
323
# Test of REPLACE when it does INSERT+DELETE and not UPDATE: