2
# Test of auto_increment; The test for BDB tables is in bdb.test
5
drop table if exists t1;
6
drop table if exists t2;
10
create TEMPORARY table t1 (a int not null auto_increment,b int, primary key (a)) engine=myisam auto_increment=3;
11
insert into t1 values (1,1),(NULL,3),(NULL,4);
12
delete from t1 where a=4;
13
insert into t1 values (NULL,5),(NULL,6);
15
delete from t1 where a=6;
16
--replace_column 1 # 6 # 7 # 8 # 9 # 10 #
17
show table status like "t1";
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);
28
skey int NOT NULL auto_increment PRIMARY KEY,
31
insert into t1 values (NULL, "hello");
32
insert into t1 values (NULL, "hey");
34
select _rowid,t1._rowid,skey,sval from t1;
38
# Test auto_increment on sub key
40
#Drizzle does not support auto_increment on sub key.
41
#create table t1 (a char(10) not null, b int not null auto_increment, primary key(b));
42
#insert into t1 values ("a",1),("b",2),("a",2),("c",1);
43
#insert into t1 values ("a",NULL),("b",NULL),("c",NULL),("e",NULL);
44
#insert into t1 (a) values ("a"),("b"),("c"),("d");
45
#insert into t1 (a) values ('k'),('d');
46
#insert into t1 (a) values ("a");
47
#insert into t1 values ("d",last_insert_id());
51
#create table t1 (ordid int(8) not null auto_increment, ord varchar(50) not null, primary key (ordid), index(ord,ordid));
52
#insert into t1 (ordid,ord) values (NULL,'sdj'),(NULL,'sdj');
56
#create table t1 (ordid int(8) not null auto_increment, ord varchar(50) not null, primary key (ord,ordid));
57
#insert into t1 values (NULL,'sdj'),(NULL,'sdj'),(NULL,"abc"),(NULL,'abc'),(NULL,'zzz'),(NULL,'sdj'),(NULL,'abc');
61
#create table t1 (sid char(5), id int(2) NOT NULL auto_increment, key(sid, id));
62
#create table t2 (sid char(20), id int(2));
63
#insert into t2 values ('skr',NULL),('skr',NULL),('test',NULL);
64
#insert into t1 select * from t2;
69
# Test of auto_increment columns when they are set to 0
72
create table t1 (a int not null primary key auto_increment);
73
insert into t1 values (0);
80
# Test negative values (Bug #1366)
83
create table t1 (a int not null auto_increment primary key);
84
insert into t1 values (NULL);
85
insert into t1 values (-1);
86
select last_insert_id();
87
insert into t1 values (NULL);
91
create temporary table t1 (a int not null auto_increment primary key) /*!40102 engine=MEMORY */;
92
insert into t1 values (NULL);
93
insert into t1 values (-1);
94
select last_insert_id();
95
insert into t1 values (NULL);
99
create table t1 (i int not null auto_increment, key (i));
100
insert into t1 set i = 254;
101
insert into t1 set i = null;
102
select last_insert_id();
103
insert into t1 set i = null;
104
select last_insert_id();
107
create table t1 (i int not null auto_increment primary key, b int, unique (b));
108
insert into t1 values (NULL, 10);
109
select last_insert_id();
110
insert into t1 values (NULL, 15);
111
select last_insert_id();
113
insert into t1 values (NULL, 10);
114
select last_insert_id();
118
create table t1(a int auto_increment,b int null,primary key(a));
119
insert into t1(a,b)values(NULL,1);
120
insert into t1(a,b)values(200,2);
121
insert into t1(a,b)values(0,3);
122
insert into t1(b)values(4);
123
insert into t1(b)values(5);
124
insert into t1(b)values(6);
125
insert into t1(b)values(7);
126
select * from t1 order by b;
127
#mediumint is not supported. changed to b int.
128
alter table t1 modify b int;
129
select * from t1 order by b;
130
create table t2 (a int);
131
insert t2 values (1),(2);
132
alter table t2 add b int auto_increment primary key;
135
delete from t1 where a=0;
136
update t1 set a=0 where b=5;
137
select * from t1 order by b;
138
delete from t1 where a=0;
139
--error ER_BAD_NULL_ERROR
140
update t1 set a=NULL where b=6;
141
update t1 set a=300 where b=7;
142
insert into t1(a,b)values(NULL,8);
143
insert into t1(a,b)values(400,9);
144
insert into t1(a,b)values(0,10);
145
insert into t1(b)values(11);
146
insert into t1(b)values(12);
147
insert into t1(b)values(13);
148
insert into t1(b)values(14);
149
select * from t1 order by b;
150
delete from t1 where a=0;
151
update t1 set a=0 where b=12;
152
select * from t1 order by b;
153
delete from t1 where a=0;
154
--error ER_BAD_NULL_ERROR
155
update t1 set a=NULL where b=13;
156
update t1 set a=500 where b=14;
157
select * from t1 order by b;
161
# Test of behavior of ALTER TABLE when coulmn containing NULL or zeroes is
162
# converted to AUTO_INCREMENT column
164
create table t1 (a bigint);
165
insert into t1 values (1), (2), (3), (NULL), (NULL);
166
alter table t1 modify a bigint not null auto_increment primary key;
170
create table t1 (a bigint);
171
insert into t1 values (1), (2), (3), (0), (0);
173
alter table t1 modify a bigint not null auto_increment primary key;
177
# We still should be able to preserve zero in NO_AUTO_VALUE_ON_ZERO mode
178
create table t1 (a bigint);
179
insert into t1 values (0), (1), (2), (3);
181
# Bug314567 - ALTER TABLE causes auto_increment resequencing,
182
# resulting in duplicate entry since sql_mode=NO_AUTO_VALUE_ON_ZERO
184
# NO_AUTO_VALUE_ON_ZERO is now default for Drizzle
186
alter table t1 modify a bigint not null auto_increment primary key;
191
# It also sensible to preserve zeroes if we are converting auto_increment
192
# column to auto_increment column (or not touching it at all, which is more
193
# common case probably)
194
create table t1 (a int auto_increment primary key , b int null);
195
#sql_mode is not supported.
196
#set sql_mode=NO_AUTO_VALUE_ON_ZERO;
197
insert into t1 values (0,1),(1,2),(2,3);
200
alter table t1 modify b varchar(255);
202
insert into t1 values (0,4);
207
# BUG #10045: Problem with composite AUTO_INCREMENT + BLOB key
209
CREATE TABLE t1 ( a INT AUTO_INCREMENT, b BLOB, PRIMARY KEY (a,b(10)));
210
INSERT INTO t1 (b) VALUES ('aaaa');
212
INSERT INTO t1 (b) VALUES ('');
214
INSERT INTO t1 (b) VALUES ('bbbb');
216
DROP TABLE IF EXISTS t1;
219
#changed syntax of int(10) to int
221
t1_name VARCHAR(255) DEFAULT NULL,
222
t1_id INT not null AUTO_INCREMENT,
225
) AUTO_INCREMENT = 1000;
227
INSERT INTO t1 (t1_name) VALUES('MySQL');
228
INSERT INTO t1 (t1_name) VALUES('MySQL');
229
INSERT INTO t1 (t1_name) VALUES('MySQL');
233
SHOW CREATE TABLE `t1`;
238
# Bug #6880: LAST_INSERT_ID() within a statement
241
create table t1(a int not null auto_increment primary key);
242
create table t2(a int not null auto_increment primary key, t1a int);
243
insert into t1 values(NULL);
244
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID());
245
insert into t1 values (NULL);
246
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()),
247
(NULL, LAST_INSERT_ID());
248
insert into t1 values (NULL);
249
insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()),
250
(NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID());
254
--echo End of 4.1 tests
257
# Bug #11080 & #11005 Multi-row REPLACE fails on a duplicate key error
259
#changed syntax of int (11) to int
260
CREATE TABLE t1 ( `a` int NOT NULL auto_increment, `b` int default NULL,PRIMARY KEY (`a`),UNIQUE KEY `b` (`b`));
261
insert into t1 (b) values (1);
262
replace into t1 (b) values (2), (1), (3);
265
insert into t1 (b) values (1);
266
replace into t1 (b) values (2);
267
replace into t1 (b) values (1);
268
replace into t1 (b) values (3);
272
create table t1 (rowid int not null auto_increment, val int not null,primary
273
key (rowid), unique(val));
274
replace into t1 (val) values ('1'),('2');
275
replace into t1 (val) values ('1'),('2');
277
insert into t1 (val) values ('1'),('2');
282
# Test that update changes internal auto-increment value
285
#create table t1 (a int not null auto_increment primary key, val int);
286
#insert into t1 (val) values (1);
287
#update t1 set a=2 where a=1;
288
#insert into t1 (val) values (1);
293
# Test key duplications with auto-increment in ALTER TABLE
296
#changed syntax of int(11) to int.
297
CREATE TABLE t1 (t1 INT PRIMARY KEY, t2 INT);
298
INSERT INTO t1 VALUES(0, 0);
299
INSERT INTO t1 VALUES(1, 1);
300
ALTER TABLE t1 CHANGE t1 t1 INT auto_increment;
302
INSERT INTO t1 VALUES(0,0);
305
# Test of REPLACE when it does INSERT+DELETE and not UPDATE:
306
# see if it sets LAST_INSERT_ID() ok
307
create table t1 (a int primary key auto_increment, b int, c int, d timestamp default current_timestamp, unique(b),unique(c));
308
insert into t1 values(null,1,1,now());
309
insert into t1 values(null,0,0,null);
310
# this will delete two rows
311
replace into t1 values(null,1,0,null);
312
select last_insert_id();