1
drop table if exists t1,t2;
2
drop database if exists mysqltest;
4
col1 int not null auto_increment primary key,
5
col2 varchar(30) not null,
6
col3 varchar (20) not null,
7
col4 varchar(4) not null,
8
col5 enum('PENDING', 'ACTIVE', 'DISABLED') not null,
9
col6 int not null, to_be_deleted int);
10
insert into t1 values (2,4,3,5,"PENDING",1,7);
12
add column col4_5 varchar(20) not null after col4,
13
add column col7 varchar(30) not null after col5,
14
add column col8 datetime not null, drop column to_be_deleted,
15
change column col2 fourth varchar(30) not null after col3,
16
modify column col6 int not null first;
18
col6 col1 col3 fourth col4 col4_5 col5 col7 col8
19
1 2 3 4 5 PENDING 0000-00-00 00:00:00
21
create table t1 (bandID INT NOT NULL PRIMARY KEY, payoutID int NOT NULL);
22
insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12);
23
alter table t1 add column new_col int;
25
bandID payoutID new_col
36
bandID payoutID new_col
47
GROUP_ID int DEFAULT '0' NOT NULL,
48
LANG_ID int DEFAULT '0' NOT NULL,
49
NAME varchar(80) DEFAULT '' NOT NULL,
50
PRIMARY KEY (GROUP_ID,LANG_ID),
52
ALTER TABLE t1 CHANGE NAME NAME CHAR(80) not null;
53
SHOW FULL COLUMNS FROM t1;
54
Field Type Collation Null Key Default Extra Privileges Comment
55
GROUP_ID int NULL NO PRI NULL #
56
LANG_ID int NULL NO PRI NULL #
57
NAME varchar(80) utf8_general_ci NO MUL NULL #
59
create table t1 (n int);
60
insert into t1 values(9),(3),(12),(10);
61
alter table t1 order by n;
70
id int NOT NULL default '0',
71
category_id int NOT NULL default '0',
72
type_id int NOT NULL default '0',
74
user_id int NOT NULL default '0',
75
status enum('new','old') NOT NULL default 'new',
78
ALTER TABLE t1 ORDER BY t1.id, t1.status, t1.type_id, t1.user_id, t1.body;
80
CREATE TABLE t1 (AnamneseId int NOT NULL auto_increment,B BLOB,PRIMARY KEY (AnamneseId)) engine=myisam;
81
insert into t1 values (null,"hello");
83
ALTER TABLE t1 ADD Column new_col int not null;
86
Table Op Msg_type Msg_text
87
test.t1 optimize status OK
89
create table t1 (i int not null auto_increment primary key);
90
insert into t1 values (null),(null),(null),(null);
91
alter table t1 drop i,add i int not null auto_increment, drop primary key, add primary key (i);
99
create table t1 (name char(15));
100
insert into t1 (name) values ("current");
101
create database mysqltest;
102
create table mysqltest.t1 (name char(15));
103
insert into mysqltest.t1 (name) values ("mysqltest");
107
select * from mysqltest.t1;
110
alter table t1 rename mysqltest.t1;
111
ERROR 42S01: Table 't1' already exists
115
select * from mysqltest.t1;
119
drop database mysqltest;
120
create table t1 (n1 int not null, n2 int, n3 int, n4 float,
122
key (n1, n2, n3, n4),
123
key (n2, n3, n4, n1),
124
key (n3, n4, n1, n2),
125
key (n4, n1, n2, n3) );
128
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
129
t1 0 n1 1 n1 NULL 0 NULL NULL BTREE
130
t1 1 n1_2 1 n1 NULL NULL NULL NULL BTREE
131
t1 1 n1_2 2 n2 NULL NULL NULL NULL YES BTREE
132
t1 1 n1_2 3 n3 NULL NULL NULL NULL YES BTREE
133
t1 1 n1_2 4 n4 NULL NULL NULL NULL YES BTREE
134
t1 1 n2 1 n2 NULL NULL NULL NULL YES BTREE
135
t1 1 n2 2 n3 NULL NULL NULL NULL YES BTREE
136
t1 1 n2 3 n4 NULL NULL NULL NULL YES BTREE
137
t1 1 n2 4 n1 NULL NULL NULL NULL BTREE
138
t1 1 n3 1 n3 NULL NULL NULL NULL YES BTREE
139
t1 1 n3 2 n4 NULL NULL NULL NULL YES BTREE
140
t1 1 n3 3 n1 NULL NULL NULL NULL BTREE
141
t1 1 n3 4 n2 NULL NULL NULL NULL YES BTREE
142
t1 1 n4 1 n4 NULL NULL NULL NULL YES BTREE
143
t1 1 n4 2 n1 NULL NULL NULL NULL BTREE
144
t1 1 n4 3 n2 NULL NULL NULL NULL YES BTREE
145
t1 1 n4 4 n3 NULL NULL NULL NULL YES BTREE
148
insert into t1 values(10,RAND()*1000,RAND()*1000,RAND());
149
insert into t1 values(9,RAND()*1000,RAND()*1000,RAND());
150
insert into t1 values(8,RAND()*1000,RAND()*1000,RAND());
151
insert into t1 values(7,RAND()*1000,RAND()*1000,RAND());
152
insert into t1 values(6,RAND()*1000,RAND()*1000,RAND());
153
insert into t1 values(5,RAND()*1000,RAND()*1000,RAND());
154
insert into t1 values(4,RAND()*1000,RAND()*1000,RAND());
155
insert into t1 values(3,RAND()*1000,RAND()*1000,RAND());
156
insert into t1 values(2,RAND()*1000,RAND()*1000,RAND());
157
insert into t1 values(1,RAND()*1000,RAND()*1000,RAND());
160
alter table t1 enable keys;
162
Note 1031 Table storage engine for 't1' doesn't have this option
164
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
165
t1 0 n1 1 n1 NULL 10 NULL NULL BTREE
166
t1 1 n1_2 1 n1 NULL NULL NULL NULL BTREE
167
t1 1 n1_2 2 n2 NULL NULL NULL NULL YES BTREE
168
t1 1 n1_2 3 n3 NULL NULL NULL NULL YES BTREE
169
t1 1 n1_2 4 n4 NULL NULL NULL NULL YES BTREE
170
t1 1 n2 1 n2 NULL NULL NULL NULL YES BTREE
171
t1 1 n2 2 n3 NULL NULL NULL NULL YES BTREE
172
t1 1 n2 3 n4 NULL NULL NULL NULL YES BTREE
173
t1 1 n2 4 n1 NULL NULL NULL NULL BTREE
174
t1 1 n3 1 n3 NULL NULL NULL NULL YES BTREE
175
t1 1 n3 2 n4 NULL NULL NULL NULL YES BTREE
176
t1 1 n3 3 n1 NULL NULL NULL NULL BTREE
177
t1 1 n3 4 n2 NULL NULL NULL NULL YES BTREE
178
t1 1 n4 1 n4 NULL NULL NULL NULL YES BTREE
179
t1 1 n4 2 n1 NULL NULL NULL NULL BTREE
180
t1 1 n4 3 n2 NULL NULL NULL NULL YES BTREE
181
t1 1 n4 4 n3 NULL NULL NULL NULL YES BTREE
183
create table t1 (i int not null auto_increment primary key);
184
alter table t1 rename t2;
185
alter table t2 rename t1, add c char(10) comment "no comment";
186
show columns from t1;
187
Field Type Null Key Default Extra
188
i int NO PRI NULL auto_increment
189
c varchar(10) YES NULL
191
create table t1 (a int, b int);
194
insert into t1 values(1,100), (2,100), (3, 100);
195
insert into t1 values(1,99), (2,99), (3, 99);
196
insert into t1 values(1,98), (2,98), (3, 98);
197
insert into t1 values(1,97), (2,97), (3, 97);
198
insert into t1 values(1,96), (2,96), (3, 96);
199
insert into t1 values(1,95), (2,95), (3, 95);
200
insert into t1 values(1,94), (2,94), (3, 94);
201
insert into t1 values(1,93), (2,93), (3, 93);
202
insert into t1 values(1,92), (2,92), (3, 92);
203
insert into t1 values(1,91), (2,91), (3, 91);
204
insert into t1 values(1,90), (2,90), (3, 90);
205
insert into t1 values(1,89), (2,89), (3, 89);
206
insert into t1 values(1,88), (2,88), (3, 88);
207
insert into t1 values(1,87), (2,87), (3, 87);
208
insert into t1 values(1,86), (2,86), (3, 86);
209
insert into t1 values(1,85), (2,85), (3, 85);
210
insert into t1 values(1,84), (2,84), (3, 84);
211
insert into t1 values(1,83), (2,83), (3, 83);
212
insert into t1 values(1,82), (2,82), (3, 82);
213
insert into t1 values(1,81), (2,81), (3, 81);
214
insert into t1 values(1,80), (2,80), (3, 80);
215
insert into t1 values(1,79), (2,79), (3, 79);
216
insert into t1 values(1,78), (2,78), (3, 78);
217
insert into t1 values(1,77), (2,77), (3, 77);
218
insert into t1 values(1,76), (2,76), (3, 76);
219
insert into t1 values(1,75), (2,75), (3, 75);
220
insert into t1 values(1,74), (2,74), (3, 74);
221
insert into t1 values(1,73), (2,73), (3, 73);
222
insert into t1 values(1,72), (2,72), (3, 72);
223
insert into t1 values(1,71), (2,71), (3, 71);
224
insert into t1 values(1,70), (2,70), (3, 70);
225
insert into t1 values(1,69), (2,69), (3, 69);
226
insert into t1 values(1,68), (2,68), (3, 68);
227
insert into t1 values(1,67), (2,67), (3, 67);
228
insert into t1 values(1,66), (2,66), (3, 66);
229
insert into t1 values(1,65), (2,65), (3, 65);
230
insert into t1 values(1,64), (2,64), (3, 64);
231
insert into t1 values(1,63), (2,63), (3, 63);
232
insert into t1 values(1,62), (2,62), (3, 62);
233
insert into t1 values(1,61), (2,61), (3, 61);
234
insert into t1 values(1,60), (2,60), (3, 60);
235
insert into t1 values(1,59), (2,59), (3, 59);
236
insert into t1 values(1,58), (2,58), (3, 58);
237
insert into t1 values(1,57), (2,57), (3, 57);
238
insert into t1 values(1,56), (2,56), (3, 56);
239
insert into t1 values(1,55), (2,55), (3, 55);
240
insert into t1 values(1,54), (2,54), (3, 54);
241
insert into t1 values(1,53), (2,53), (3, 53);
242
insert into t1 values(1,52), (2,52), (3, 52);
243
insert into t1 values(1,51), (2,51), (3, 51);
244
insert into t1 values(1,50), (2,50), (3, 50);
245
insert into t1 values(1,49), (2,49), (3, 49);
246
insert into t1 values(1,48), (2,48), (3, 48);
247
insert into t1 values(1,47), (2,47), (3, 47);
248
insert into t1 values(1,46), (2,46), (3, 46);
249
insert into t1 values(1,45), (2,45), (3, 45);
250
insert into t1 values(1,44), (2,44), (3, 44);
251
insert into t1 values(1,43), (2,43), (3, 43);
252
insert into t1 values(1,42), (2,42), (3, 42);
253
insert into t1 values(1,41), (2,41), (3, 41);
254
insert into t1 values(1,40), (2,40), (3, 40);
255
insert into t1 values(1,39), (2,39), (3, 39);
256
insert into t1 values(1,38), (2,38), (3, 38);
257
insert into t1 values(1,37), (2,37), (3, 37);
258
insert into t1 values(1,36), (2,36), (3, 36);
259
insert into t1 values(1,35), (2,35), (3, 35);
260
insert into t1 values(1,34), (2,34), (3, 34);
261
insert into t1 values(1,33), (2,33), (3, 33);
262
insert into t1 values(1,32), (2,32), (3, 32);
263
insert into t1 values(1,31), (2,31), (3, 31);
264
insert into t1 values(1,30), (2,30), (3, 30);
265
insert into t1 values(1,29), (2,29), (3, 29);
266
insert into t1 values(1,28), (2,28), (3, 28);
267
insert into t1 values(1,27), (2,27), (3, 27);
268
insert into t1 values(1,26), (2,26), (3, 26);
269
insert into t1 values(1,25), (2,25), (3, 25);
270
insert into t1 values(1,24), (2,24), (3, 24);
271
insert into t1 values(1,23), (2,23), (3, 23);
272
insert into t1 values(1,22), (2,22), (3, 22);
273
insert into t1 values(1,21), (2,21), (3, 21);
274
insert into t1 values(1,20), (2,20), (3, 20);
275
insert into t1 values(1,19), (2,19), (3, 19);
276
insert into t1 values(1,18), (2,18), (3, 18);
277
insert into t1 values(1,17), (2,17), (3, 17);
278
insert into t1 values(1,16), (2,16), (3, 16);
279
insert into t1 values(1,15), (2,15), (3, 15);
280
insert into t1 values(1,14), (2,14), (3, 14);
281
insert into t1 values(1,13), (2,13), (3, 13);
282
insert into t1 values(1,12), (2,12), (3, 12);
283
insert into t1 values(1,11), (2,11), (3, 11);
284
insert into t1 values(1,10), (2,10), (3, 10);
285
insert into t1 values(1,9), (2,9), (3, 9);
286
insert into t1 values(1,8), (2,8), (3, 8);
287
insert into t1 values(1,7), (2,7), (3, 7);
288
insert into t1 values(1,6), (2,6), (3, 6);
289
insert into t1 values(1,5), (2,5), (3, 5);
290
insert into t1 values(1,4), (2,4), (3, 4);
291
insert into t1 values(1,3), (2,3), (3, 3);
292
insert into t1 values(1,2), (2,2), (3, 2);
293
insert into t1 values(1,1), (2,1), (3, 1);
296
alter table t1 add unique (a,b), add key (b);
298
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
299
t1 0 a 1 a A NULL NULL NULL YES BTREE
300
t1 0 a 2 b A NULL NULL NULL YES BTREE
301
t1 1 b 1 b A NULL NULL NULL YES BTREE
303
Table Op Msg_type Msg_text
304
test.t1 analyze status OK
306
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
307
t1 0 a 1 a A NULL NULL NULL YES BTREE
308
t1 0 a 2 b A NULL NULL NULL YES BTREE
309
t1 1 b 1 b A NULL NULL NULL YES BTREE
312
Host varchar(16) binary NOT NULL default '',
313
User varchar(16) binary NOT NULL default '',
314
PRIMARY KEY (Host,User)
316
ALTER TABLE t1 DISABLE KEYS;
317
LOCK TABLES t1 WRITE;
318
INSERT INTO t1 VALUES ('localhost','root'),('localhost',''),('games','monty');
320
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
321
t1 0 PRIMARY 1 Host A NULL NULL NULL BTREE
322
t1 0 PRIMARY 2 User A 0 NULL NULL BTREE
323
ALTER TABLE t1 ENABLE KEYS;
326
Table Op Msg_type Msg_text
327
test.t1 check status OK
330
Host varchar(16) binary NOT NULL default '',
331
User varchar(16) binary NOT NULL default '',
332
PRIMARY KEY (Host,User),
335
ALTER TABLE t1 DISABLE KEYS;
337
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
338
t1 0 PRIMARY 1 Host A NULL NULL NULL BTREE
339
t1 0 PRIMARY 2 User A 0 NULL NULL BTREE
340
t1 1 Host 1 Host A NULL NULL NULL BTREE disabled
341
LOCK TABLES t1 WRITE;
342
INSERT INTO t1 VALUES ('localhost','root'),('localhost','');
344
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
345
t1 0 PRIMARY 1 Host A NULL NULL NULL BTREE
346
t1 0 PRIMARY 2 User A 0 NULL NULL BTREE
347
t1 1 Host 1 Host A NULL NULL NULL BTREE disabled
348
ALTER TABLE t1 ENABLE KEYS;
350
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
351
t1 0 PRIMARY 1 Host A NULL NULL NULL BTREE
352
t1 0 PRIMARY 2 User A 2 NULL NULL BTREE
353
t1 1 Host 1 Host A 1 NULL NULL BTREE
356
Table Op Msg_type Msg_text
357
test.t1 check status OK
358
LOCK TABLES t1 WRITE;
359
ALTER TABLE t1 RENAME t2;
367
Host varchar(16) binary NOT NULL default '',
368
User varchar(16) binary NOT NULL default '',
369
PRIMARY KEY (Host,User),
372
LOCK TABLES t1 WRITE;
373
ALTER TABLE t1 DISABLE KEYS;
375
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
376
t1 0 PRIMARY 1 Host A NULL NULL NULL BTREE
377
t1 0 PRIMARY 2 User A 0 NULL NULL BTREE
378
t1 1 Host 1 Host A NULL NULL NULL BTREE disabled
380
create table t1 (a int);
381
alter table t1 rename to ``;
382
ERROR 42000: Incorrect table name ''
383
rename table t1 to ``;
384
ERROR 42000: Incorrect table name ''
386
drop table if exists t1;
388
Note 1051 Unknown table 't1'
389
create table t1 ( a varchar(10) not null primary key ) engine=myisam;
391
alter table t1 modify a varchar(10);
393
alter table t1 modify a varchar(10) not null;
394
drop table if exists t1;
395
create table t1 (a int, b int, c int, d int, e int, f int, g int, h int,i int, primary key (a,b,c,d,e,f,g,i,h)) engine=MyISAM;
396
insert into t1 (a) values(1);
397
show table status like 't1';
398
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
399
t1 MyISAM 10 Fixed 1 37 X X X X X X X X utf8_general_ci NULL
400
alter table t1 modify a int;
401
show table status like 't1';
402
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
403
t1 MyISAM 10 Fixed 1 37 X X X X X X X X utf8_general_ci NULL
405
create table t1 (a int not null default 0, b int not null default 0, c int not null default 0, d int not null default 0, e int not null default 0, f int not null default 0, g int not null default 0, h int not null default 0,i int not null default 0, primary key (a,b,c,d,e,f,g,i,h)) engine=MyISAM;
406
insert into t1 (a) values(1);
407
show table status like 't1';
408
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
409
t1 MyISAM 10 Fixed 1 37 X X X X X X X X utf8_general_ci NULL
411
CREATE TABLE t1 (a int PRIMARY KEY, b INT UNIQUE);
412
ALTER TABLE t1 DROP PRIMARY KEY;
413
SHOW CREATE TABLE t1;
415
t1 CREATE TABLE `t1` (
420
ALTER TABLE t1 DROP PRIMARY KEY;
421
ERROR 42000: Can't DROP 'PRIMARY'; check that column/key exists
423
create table t1 (a int, b int, key(a));
424
insert into t1 values (1,1), (2,2);
425
alter table t1 drop key no_such_key;
426
ERROR 42000: Can't DROP 'no_such_key'; check that column/key exists
427
alter table t1 drop key a;
429
CREATE TABLE T12207(a int) ENGINE=MYISAM;
430
ALTER TABLE T12207 DISCARD TABLESPACE;
431
ERROR HY000: Table storage engine for 'T12207' doesn't have this option
433
create table t1 ( a timestamp );
434
alter table t1 add unique ( a(1) );
435
ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys
437
drop table if exists t1;
438
create table t1 (a int, key(a));
439
show indexes from t1;
440
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
441
t1 1 a 1 a A NULL NULL NULL YES BTREE
442
"this used not to disable the index"
443
alter table t1 modify a int;
444
show indexes from t1;
445
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
446
t1 1 a 1 a A NULL NULL NULL YES BTREE
447
alter table t1 enable keys;
449
Note 1031 Table storage engine for 't1' doesn't have this option
450
show indexes from t1;
451
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
452
t1 1 a 1 a NULL NULL NULL NULL YES BTREE
453
alter table t1 modify a bigint;
454
show indexes from t1;
455
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
456
t1 1 a 1 a A NULL NULL NULL YES BTREE
457
alter table t1 enable keys;
459
Note 1031 Table storage engine for 't1' doesn't have this option
460
show indexes from t1;
461
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
462
t1 1 a 1 a NULL NULL NULL NULL YES BTREE
463
alter table t1 add b char(10);
464
show indexes from t1;
465
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
466
t1 1 a 1 a A NULL NULL NULL YES BTREE
467
alter table t1 add c decimal(10,2);
468
show indexes from t1;
469
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
470
t1 1 a 1 a A NULL NULL NULL YES BTREE
473
show indexes from t1;
474
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
475
t1 1 a 1 a NULL NULL NULL NULL YES BTREE
477
Field Type Null Key Default Extra
478
a bigint YES MUL NULL
479
b varchar(10) YES NULL
480
c decimal(10,2) YES NULL
481
alter table t1 add d decimal(15,5);
482
"The key should still be disabled"
483
show indexes from t1;
484
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
485
t1 1 a 1 a A NULL NULL NULL YES BTREE
487
"Now will test with one unique index"
488
create table t1(a int, b char(10), unique(a));
489
show indexes from t1;
490
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
491
t1 0 a 1 a A 0 NULL NULL YES BTREE
493
show indexes from t1;
494
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
495
t1 0 a 1 a NULL 0 NULL NULL YES BTREE
496
alter table t1 enable keys;
498
Note 1031 Table storage engine for 't1' doesn't have this option
499
"If no copy on noop change, this won't touch the data file"
500
"Unique index, no change"
501
alter table t1 modify a int;
502
show indexes from t1;
503
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
504
t1 0 a 1 a A 0 NULL NULL YES BTREE
505
"Change the type implying data copy"
506
"Unique index, no change"
507
alter table t1 modify a bigint;
508
show indexes from t1;
509
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
510
t1 0 a 1 a A 0 NULL NULL YES BTREE
511
alter table t1 modify a bigint;
512
show indexes from t1;
513
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
514
t1 0 a 1 a A 0 NULL NULL YES BTREE
515
alter table t1 modify a int;
516
show indexes from t1;
517
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
518
t1 0 a 1 a A 0 NULL NULL YES BTREE
520
"Now will test with one unique and one non-unique index"
521
create table t1(a int, b char(10), unique(a), key(b));
522
show indexes from t1;
523
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
524
t1 0 a 1 a A 0 NULL NULL YES BTREE
525
t1 1 b 1 b A NULL NULL NULL YES BTREE
527
show indexes from t1;
528
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
529
t1 0 a 1 a NULL 0 NULL NULL YES BTREE
530
t1 1 b 1 b NULL NULL NULL NULL YES BTREE
531
alter table t1 enable keys;
533
Note 1031 Table storage engine for 't1' doesn't have this option
534
"If no copy on noop change, this won't touch the data file"
535
"The non-unique index will be disabled"
536
alter table t1 modify a int;
537
show indexes from t1;
538
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
539
t1 0 a 1 a A 0 NULL NULL YES BTREE
540
t1 1 b 1 b A NULL NULL NULL YES BTREE
541
alter table t1 enable keys;
543
Note 1031 Table storage engine for 't1' doesn't have this option
544
show indexes from t1;
545
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
546
t1 0 a 1 a NULL 0 NULL NULL YES BTREE
547
t1 1 b 1 b NULL NULL NULL NULL YES BTREE
548
"Change the type implying data copy"
549
"The non-unique index will be disabled"
550
alter table t1 modify a bigint;
551
show indexes from t1;
552
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
553
t1 0 a 1 a A 0 NULL NULL YES BTREE
554
t1 1 b 1 b A NULL NULL NULL YES BTREE
555
"Change again the type, but leave the indexes as_is"
556
alter table t1 modify a int;
557
show indexes from t1;
558
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
559
t1 0 a 1 a A 0 NULL NULL YES BTREE
560
t1 1 b 1 b A NULL NULL NULL YES BTREE
561
"Try the same. When data is no copied on similar tables, this is noop"
562
alter table t1 modify a int;
563
show indexes from t1;
564
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
565
t1 0 a 1 a A 0 NULL NULL YES BTREE
566
t1 1 b 1 b A NULL NULL NULL YES BTREE
568
create database mysqltest;
569
create table t1 (c1 int);
570
alter table t1 rename mysqltest.t1;
572
ERROR 42S02: Unknown table 't1'
573
alter table mysqltest.t1 rename t1;
575
create table t1 (c1 int);
577
drop database mysqltest;
578
alter table test.t1 rename t1;
579
ERROR 3D000: No database selected
580
alter table test.t1 rename test.t1;
583
CREATE TABLE t1(a INT) ROW_FORMAT=FIXED;
584
CREATE INDEX i1 ON t1(a);
585
SHOW CREATE TABLE t1;
587
t1 CREATE TABLE `t1` (
590
) ENGINE=PBXT ROW_FORMAT=FIXED
592
SHOW CREATE TABLE t1;
594
t1 CREATE TABLE `t1` (
596
) ENGINE=PBXT ROW_FORMAT=FIXED
598
DROP TABLE IF EXISTS bug24219;
599
DROP TABLE IF EXISTS bug24219_2;
600
CREATE TABLE bug24219 (a INT, INDEX(a));
601
SHOW INDEX FROM bug24219;
602
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
603
bug24219 1 a 1 a A NULL NULL NULL YES BTREE
604
ALTER TABLE bug24219 RENAME TO bug24219_2, DISABLE KEYS;
606
Note 1031 Table storage engine for 'bug24219' doesn't have this option
607
SHOW INDEX FROM bug24219_2;
608
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
609
bug24219_2 1 a 1 a A NULL NULL NULL YES BTREE
610
DROP TABLE bug24219_2;
611
drop table if exists table_24562;
612
create table table_24562(
616
insert into table_24562 values
617
(1, 0, "Introduction"),
619
(1, 2, "Acknowledgements"),
624
(3, 0, "Intermediate"),
625
(3, 1, "Complex queries"),
626
(3, 2, "Stored Procedures"),
627
(3, 3, "Stored Functions"),
629
(4, 1, "Replication"),
630
(4, 2, "Load balancing"),
631
(4, 3, "High availability"),
632
(5, 0, "Conclusion");
633
select * from table_24562;
634
section subsection title
644
3 2 Stored Procedures
649
4 3 High availability
651
alter table table_24562 add column reviewer varchar(20),
653
select * from table_24562;
654
section subsection title reviewer
655
1 2 Acknowledgements NULL
660
3 1 Complex queries NULL
662
4 3 High availability NULL
663
3 0 Intermediate NULL
664
1 0 Introduction NULL
665
4 2 Load balancing NULL
668
3 3 Stored Functions NULL
669
3 2 Stored Procedures NULL
671
update table_24562 set reviewer="Me" where section=2;
672
update table_24562 set reviewer="You" where section=3;
673
alter table table_24562
674
order by section ASC, subsection DESC;
675
select * from table_24562;
676
section subsection title reviewer
677
1 2 Acknowledgements NULL
679
1 0 Introduction NULL
684
3 3 Stored Functions You
685
3 2 Stored Procedures You
686
3 1 Complex queries You
688
4 3 High availability NULL
689
4 2 Load balancing NULL
693
alter table table_24562
694
order by table_24562.subsection ASC, table_24562.section DESC;
695
select * from table_24562;
696
section subsection title reviewer
701
1 0 Introduction NULL
703
3 1 Complex queries You
706
4 2 Load balancing NULL
707
3 2 Stored Procedures You
709
1 2 Acknowledgements NULL
710
4 3 High availability NULL
711
3 3 Stored Functions You
713
alter table table_24562 order by 12;
714
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '12' at line 1
715
alter table table_24562 order by (section + 12);
716
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(section + 12)' at line 1
717
alter table table_24562 order by length(title);
718
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(title)' at line 1
719
alter table table_24562 order by no_such_col;
720
ERROR 42S22: Unknown column 'no_such_col' in 'order clause'
721
drop table table_24562;
722
create table t1 (mycol int not null);
723
alter table t1 alter column mycol set default 0;
725
Field Type Null Key Default Extra
728
create table t1(id int primary key auto_increment) engine=heap;
729
insert into t1 values (null);
730
insert into t1 values (null);
735
alter table t1 auto_increment = 50;
736
alter table t1 engine = myisam;
737
insert into t1 values (null);
743
alter table t1 engine = heap;
744
insert into t1 values (null);
752
create table t1 (v varchar(32));
753
insert into t1 values ('def'),('abc'),('hij'),('3r4f');
760
alter table t1 change v v2 varchar(32);
767
alter table t1 change v2 v varchar(64);
774
update t1 set v = 'lmn' where v = 'hij';
781
alter table t1 add i int auto_increment not null primary key first;
788
update t1 set i=5 where i=3;
795
alter table t1 change i i bigint;
802
alter table t1 add unique key (i, v);
803
select * from t1 where i between 2 and 4 and v in ('def','3r4f','lmn');
807
create table t1 (t varchar(255) default null, key t (t(80))) engine=myisam;
808
alter table t1 change t t text;
810
CREATE TABLE t1 (s CHAR(8) BINARY);
811
INSERT INTO t1 VALUES ('test');
812
SELECT LENGTH(s) FROM t1;
815
ALTER TABLE t1 MODIFY s CHAR(10) BINARY;
816
SELECT LENGTH(s) FROM t1;
820
CREATE TABLE t1 (s varbinary(8));
821
INSERT INTO t1 VALUES ('test');
822
SELECT LENGTH(s) FROM t1;
825
SELECT HEX(s) FROM t1;
828
ALTER TABLE t1 MODIFY s varbinary(10);
829
SELECT HEX(s) FROM t1;
832
SELECT LENGTH(s) FROM t1;
836
CREATE TABLE t1 (v VARCHAR(3), b INT);
837
INSERT INTO t1 VALUES ('abc', 5);
841
ALTER TABLE t1 MODIFY COLUMN v VARCHAR(4);
847
drop table if exists t1, t2, t3;
848
create table t1 (i int);
849
create table t3 (j int);
850
insert into t1 values ();
851
insert into t3 values ();
852
lock table t1 write, t3 read;
853
alter table t1 modify i int default 1;
854
insert into t1 values ();
859
alter table t1 change i c char(10) default "Two";
860
insert into t1 values ();
866
alter table t1 modify c char(10) default "Three", rename to t2;
868
ERROR HY000: Table 't1' was not locked with LOCK TABLES
870
ERROR HY000: Table 't2' was not locked with LOCK TABLES
875
insert into t2 values ();
882
lock table t2 write, t3 read;
883
alter table t2 change c vc varchar(100) default "Four", rename to t1;
885
ERROR HY000: Table 't1' was not locked with LOCK TABLES
887
ERROR HY000: Table 't2' was not locked with LOCK TABLES
892
insert into t1 values ();
901
DROP TABLE IF EXISTS `t+1`, `t+2`;
902
CREATE TABLE `t+1` (c1 INT);
903
ALTER TABLE `t+1` RENAME `t+2`;
904
CREATE TABLE `t+1` (c1 INT);
905
ALTER TABLE `t+1` RENAME `t+2`;
906
ERROR 42S01: Table 't+2' already exists
907
DROP TABLE `t+1`, `t+2`;
908
CREATE TEMPORARY TABLE `tt+1` (c1 INT);
909
ALTER TABLE `tt+1` RENAME `tt+2`;
910
CREATE TEMPORARY TABLE `tt+1` (c1 INT);
911
ALTER TABLE `tt+1` RENAME `tt+2`;
912
ERROR 42S01: Table 'tt+2' already exists
913
SHOW CREATE TABLE `tt+1`;
915
tt+1 CREATE TEMPORARY TABLE `tt+1` (
918
SHOW CREATE TABLE `tt+2`;
920
tt+2 CREATE TEMPORARY TABLE `tt+2` (
923
DROP TABLE `tt+1`, `tt+2`;
924
CREATE TEMPORARY TABLE `#sql1` (c1 INT);
925
CREATE TEMPORARY TABLE `@0023sql2` (c1 INT);
928
ALTER TABLE `#sql1` RENAME `@0023sql1`;
929
ALTER TABLE `@0023sql2` RENAME `#sql2`;
932
INSERT INTO `#sql2` VALUES (1);
933
INSERT INTO `@0023sql1` VALUES (2);
934
SHOW CREATE TABLE `#sql2`;
936
#sql2 CREATE TEMPORARY TABLE `#sql2` (
939
SHOW CREATE TABLE `@0023sql1`;
941
@0023sql1 CREATE TEMPORARY TABLE `@0023sql1` (
944
DROP TABLE `#sql2`, `@0023sql1`;
945
DROP TABLE IF EXISTS t1;
946
DROP TABLE IF EXISTS t2;
948
int_field INTEGER NOT NULL,
953
Field Type Null Key Default Extra
954
int_field int NO MUL NULL
955
char_field varchar(10) YES NULL
956
SHOW INDEXES FROM t1;
957
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
958
t1 1 int_field 1 int_field A NULL NULL NULL BTREE
959
INSERT INTO t1 VALUES (1, "edno"), (1, "edno"), (2, "dve"), (3, "tri"), (5, "pet");
960
"Non-copy data change - new frm, but old data and index files"
961
ALTER TABLE t1 CHANGE int_field unsigned_int_field INTEGER NOT NULL, RENAME t2;
962
SELECT * FROM t1 ORDER BY int_field;
963
ERROR 42S02: Table 'test.t1' doesn't exist
964
SELECT * FROM t2 ORDER BY unsigned_int_field;
965
unsigned_int_field char_field
972
Field Type Null Key Default Extra
973
unsigned_int_field int NO MUL NULL
974
char_field varchar(10) YES NULL
976
Field Type Null Key Default Extra
977
unsigned_int_field int NO MUL NULL
978
char_field varchar(10) YES NULL
979
ALTER TABLE t2 MODIFY unsigned_int_field BIGINT NOT NULL;
981
Field Type Null Key Default Extra
982
unsigned_int_field bigint NO MUL NULL
983
char_field varchar(10) YES NULL
985
CREATE TABLE t1 (f1 INT, f2 INT, f3 INT);
986
INSERT INTO t1 VALUES (1, 2, NULL);
990
ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f1;
994
ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f2;
999
create table t1 (c char(10) default "Two");
1000
lock table t1 write;
1001
insert into t1 values ();
1002
alter table t1 modify c char(10) default "Three";
1008
Table Op Msg_type Msg_text
1009
test.t1 check status OK