~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/pbxt/alter_table.result

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
drop table if exists t1,t2;
 
2
drop database if exists mysqltest;
 
3
create table t1 (
 
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);
 
11
alter table t1
 
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;
 
17
select * from t1;
 
18
col6    col1    col3    fourth  col4    col4_5  col5    col7    col8
 
19
1       2       3       4       5               PENDING         0000-00-00 00:00:00
 
20
drop table t1;
 
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;
 
24
select * from t1;
 
25
bandID  payoutID        new_col
 
26
1       6       NULL
 
27
2       6       NULL
 
28
3       4       NULL
 
29
4       9       NULL
 
30
5       10      NULL
 
31
6       1       NULL
 
32
7       12      NULL
 
33
8       12      NULL
 
34
alter table t1;
 
35
select * from t1;
 
36
bandID  payoutID        new_col
 
37
1       6       NULL
 
38
2       6       NULL
 
39
3       4       NULL
 
40
4       9       NULL
 
41
5       10      NULL
 
42
6       1       NULL
 
43
7       12      NULL
 
44
8       12      NULL
 
45
drop table t1;
 
46
CREATE TABLE t1 (
 
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),
 
51
KEY NAME (NAME));
 
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            #       
 
58
DROP TABLE t1;
 
59
create table t1 (n int);
 
60
insert into t1 values(9),(3),(12),(10);
 
61
alter table t1 order by n;
 
62
select * from t1;
 
63
n
 
64
3
 
65
9
 
66
10
 
67
12
 
68
drop table t1;
 
69
CREATE TABLE t1 (
 
70
id int NOT NULL default '0',
 
71
category_id int NOT NULL default '0',
 
72
type_id int NOT NULL default '0',
 
73
body text NOT NULL,
 
74
user_id int NOT NULL default '0',
 
75
status enum('new','old') NOT NULL default 'new',
 
76
PRIMARY KEY (id)
 
77
) ENGINE=MyISAM;
 
78
ALTER TABLE t1 ORDER BY t1.id, t1.status, t1.type_id, t1.user_id, t1.body;
 
79
DROP TABLE t1;
 
80
CREATE TABLE t1 (AnamneseId int NOT NULL auto_increment,B BLOB,PRIMARY KEY (AnamneseId)) engine=myisam;
 
81
insert into t1 values (null,"hello");
 
82
LOCK TABLES t1 WRITE;
 
83
ALTER TABLE t1 ADD Column new_col int not null;
 
84
UNLOCK TABLES;
 
85
OPTIMIZE TABLE t1;
 
86
Table   Op      Msg_type        Msg_text
 
87
test.t1 optimize        status  OK
 
88
DROP TABLE t1;
 
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);
 
92
select * from t1;
 
93
i
 
94
1
 
95
2
 
96
3
 
97
4
 
98
drop table t1;
 
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");
 
104
select * from t1;
 
105
name
 
106
current
 
107
select * from mysqltest.t1;
 
108
name
 
109
mysqltest
 
110
alter table t1 rename mysqltest.t1;
 
111
ERROR 42S01: Table 't1' already exists
 
112
select * from t1;
 
113
name
 
114
current
 
115
select * from mysqltest.t1;
 
116
name
 
117
mysqltest
 
118
drop table t1;
 
119
drop database mysqltest;
 
120
create table t1 (n1 int not null, n2 int, n3 int, n4 float,
 
121
unique(n1),
 
122
key (n1, n2, n3, n4),
 
123
key (n2, n3, n4, n1),
 
124
key (n3, n4, n1, n2),
 
125
key (n4, n1, n2, n3) );
 
126
alter table t1;
 
127
show keys from t1;
 
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           
 
146
set autocommit=0;
 
147
begin;
 
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());
 
158
commit;
 
159
set autocommit=1;
 
160
alter table t1 enable keys;
 
161
Warnings:
 
162
Note    1031    Table storage engine for 't1' doesn't have this option
 
163
show keys from t1;
 
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           
 
182
drop table t1;
 
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    
 
190
drop table t1;
 
191
create table t1 (a int, b int);
 
192
set autocommit=0;
 
193
begin;
 
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);
 
294
commit;
 
295
set autocommit=1;
 
296
alter table t1 add unique (a,b), add key (b);
 
297
show keys from t1;
 
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           
 
302
analyze table t1;
 
303
Table   Op      Msg_type        Msg_text
 
304
test.t1 analyze status  OK
 
305
show keys from t1;
 
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           
 
310
drop table t1;
 
311
CREATE TABLE t1 (
 
312
Host varchar(16) binary NOT NULL default '',
 
313
User varchar(16) binary NOT NULL default '',
 
314
PRIMARY KEY  (Host,User)
 
315
) ENGINE=MyISAM;
 
316
ALTER TABLE t1 DISABLE KEYS;
 
317
LOCK TABLES t1 WRITE;
 
318
INSERT INTO t1 VALUES ('localhost','root'),('localhost',''),('games','monty');
 
319
SHOW INDEX FROM t1;
 
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;
 
324
UNLOCK TABLES;
 
325
CHECK TABLES t1;
 
326
Table   Op      Msg_type        Msg_text
 
327
test.t1 check   status  OK
 
328
DROP TABLE t1;
 
329
CREATE TABLE t1 (
 
330
Host varchar(16) binary NOT NULL default '',
 
331
User varchar(16) binary NOT NULL default '',
 
332
PRIMARY KEY  (Host,User),
 
333
KEY  (Host)
 
334
) ENGINE=MyISAM;
 
335
ALTER TABLE t1 DISABLE KEYS;
 
336
SHOW INDEX FROM t1;
 
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','');
 
343
SHOW INDEX FROM t1;
 
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;
 
349
SHOW INDEX FROM t1;
 
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           
 
354
UNLOCK TABLES;
 
355
CHECK TABLES t1;
 
356
Table   Op      Msg_type        Msg_text
 
357
test.t1 check   status  OK
 
358
LOCK TABLES t1 WRITE;
 
359
ALTER TABLE t1 RENAME t2;
 
360
UNLOCK TABLES;
 
361
select * from t2;
 
362
Host    User
 
363
localhost       
 
364
localhost       root
 
365
DROP TABLE t2;
 
366
CREATE TABLE t1 (
 
367
Host varchar(16) binary NOT NULL default '',
 
368
User varchar(16) binary NOT NULL default '',
 
369
PRIMARY KEY  (Host,User),
 
370
KEY  (Host)
 
371
) ENGINE=MyISAM;
 
372
LOCK TABLES t1 WRITE;
 
373
ALTER TABLE t1 DISABLE KEYS;
 
374
SHOW INDEX FROM t1;
 
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        
 
379
DROP TABLE t1;
 
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 ''
 
385
drop table t1;
 
386
drop table if exists t1;
 
387
Warnings:
 
388
Note    1051    Unknown table 't1'
 
389
create table t1 ( a varchar(10) not null primary key ) engine=myisam;
 
390
flush tables;
 
391
alter table t1 modify a varchar(10);
 
392
flush tables;
 
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            
 
404
drop table t1;
 
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            
 
410
drop table t1;
 
411
CREATE TABLE t1 (a int PRIMARY KEY, b INT UNIQUE);
 
412
ALTER TABLE t1 DROP PRIMARY KEY;
 
413
SHOW CREATE TABLE t1;
 
414
Table   Create Table
 
415
t1      CREATE TABLE `t1` (
 
416
  `a` int NOT NULL,
 
417
  `b` int,
 
418
  UNIQUE KEY `b` (`b`)
 
419
) ENGINE=PBXT
 
420
ALTER TABLE t1 DROP PRIMARY KEY;
 
421
ERROR 42000: Can't DROP 'PRIMARY'; check that column/key exists
 
422
DROP TABLE t1;
 
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;
 
428
drop table t1;
 
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
 
432
DROP TABLE T12207;
 
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
 
436
drop table t1;
 
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;
 
448
Warnings:
 
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;
 
458
Warnings:
 
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           
 
471
"this however did"
 
472
alter table t1;
 
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           
 
476
desc t1;
 
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           
 
486
drop table t1;
 
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           
 
492
alter table t1;
 
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;
 
497
Warnings:
 
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           
 
519
drop table t1;
 
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           
 
526
alter table t1;
 
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;
 
532
Warnings:
 
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;
 
542
Warnings:
 
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           
 
567
drop table t1;
 
568
create database mysqltest;
 
569
create table t1 (c1 int);
 
570
alter table t1 rename mysqltest.t1;
 
571
drop table t1;
 
572
ERROR 42S02: Unknown table 't1'
 
573
alter table mysqltest.t1 rename t1;
 
574
drop table t1;
 
575
create table t1 (c1 int);
 
576
use mysqltest;
 
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;
 
581
use test;
 
582
drop table t1;
 
583
CREATE TABLE t1(a INT) ROW_FORMAT=FIXED;
 
584
CREATE INDEX i1 ON t1(a);
 
585
SHOW CREATE TABLE t1;
 
586
Table   Create Table
 
587
t1      CREATE TABLE `t1` (
 
588
  `a` int,
 
589
  KEY `i1` (`a`)
 
590
) ENGINE=PBXT ROW_FORMAT=FIXED
 
591
DROP INDEX i1 ON t1;
 
592
SHOW CREATE TABLE t1;
 
593
Table   Create Table
 
594
t1      CREATE TABLE `t1` (
 
595
  `a` int
 
596
) ENGINE=PBXT ROW_FORMAT=FIXED
 
597
DROP TABLE t1;
 
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;
 
605
Warnings:
 
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(
 
613
section int,
 
614
subsection int,
 
615
title varchar(50));
 
616
insert into table_24562 values
 
617
(1, 0, "Introduction"),
 
618
(1, 1, "Authors"),
 
619
(1, 2, "Acknowledgements"),
 
620
(2, 0, "Basics"),
 
621
(2, 1, "Syntax"),
 
622
(2, 2, "Client"),
 
623
(2, 3, "Server"),
 
624
(3, 0, "Intermediate"),
 
625
(3, 1, "Complex queries"),
 
626
(3, 2, "Stored Procedures"),
 
627
(3, 3, "Stored Functions"),
 
628
(4, 0, "Advanced"),
 
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
 
635
1       0       Introduction
 
636
1       1       Authors
 
637
1       2       Acknowledgements
 
638
2       0       Basics
 
639
2       1       Syntax
 
640
2       2       Client
 
641
2       3       Server
 
642
3       0       Intermediate
 
643
3       1       Complex queries
 
644
3       2       Stored Procedures
 
645
3       3       Stored Functions
 
646
4       0       Advanced
 
647
4       1       Replication
 
648
4       2       Load balancing
 
649
4       3       High availability
 
650
5       0       Conclusion
 
651
alter table table_24562 add column reviewer varchar(20),
 
652
order by title;
 
653
select * from table_24562;
 
654
section subsection      title   reviewer
 
655
1       2       Acknowledgements        NULL
 
656
4       0       Advanced        NULL
 
657
1       1       Authors NULL
 
658
2       0       Basics  NULL
 
659
2       2       Client  NULL
 
660
3       1       Complex queries NULL
 
661
5       0       Conclusion      NULL
 
662
4       3       High availability       NULL
 
663
3       0       Intermediate    NULL
 
664
1       0       Introduction    NULL
 
665
4       2       Load balancing  NULL
 
666
4       1       Replication     NULL
 
667
2       3       Server  NULL
 
668
3       3       Stored Functions        NULL
 
669
3       2       Stored Procedures       NULL
 
670
2       1       Syntax  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
 
678
1       1       Authors NULL
 
679
1       0       Introduction    NULL
 
680
2       3       Server  Me
 
681
2       2       Client  Me
 
682
2       1       Syntax  Me
 
683
2       0       Basics  Me
 
684
3       3       Stored Functions        You
 
685
3       2       Stored Procedures       You
 
686
3       1       Complex queries You
 
687
3       0       Intermediate    You
 
688
4       3       High availability       NULL
 
689
4       2       Load balancing  NULL
 
690
4       1       Replication     NULL
 
691
4       0       Advanced        NULL
 
692
5       0       Conclusion      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
 
697
5       0       Conclusion      NULL
 
698
4       0       Advanced        NULL
 
699
3       0       Intermediate    You
 
700
2       0       Basics  Me
 
701
1       0       Introduction    NULL
 
702
4       1       Replication     NULL
 
703
3       1       Complex queries You
 
704
2       1       Syntax  Me
 
705
1       1       Authors NULL
 
706
4       2       Load balancing  NULL
 
707
3       2       Stored Procedures       You
 
708
2       2       Client  Me
 
709
1       2       Acknowledgements        NULL
 
710
4       3       High availability       NULL
 
711
3       3       Stored Functions        You
 
712
2       3       Server  Me
 
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;
 
724
desc t1;
 
725
Field   Type    Null    Key     Default Extra
 
726
mycol   int     NO              NULL    
 
727
drop table t1;
 
728
create table t1(id int primary key auto_increment) engine=heap;
 
729
insert into t1 values (null);
 
730
insert into t1 values (null);
 
731
select * from t1;
 
732
id
 
733
1
 
734
2
 
735
alter table t1 auto_increment = 50;
 
736
alter table t1 engine = myisam;
 
737
insert into t1 values (null);
 
738
select * from t1;
 
739
id
 
740
1
 
741
2
 
742
50
 
743
alter table t1 engine = heap;
 
744
insert into t1 values (null);
 
745
select * from t1;
 
746
id
 
747
1
 
748
2
 
749
50
 
750
51
 
751
drop table t1;
 
752
create table t1 (v varchar(32));
 
753
insert into t1 values ('def'),('abc'),('hij'),('3r4f');
 
754
select * from t1;
 
755
v
 
756
def
 
757
abc
 
758
hij
 
759
3r4f
 
760
alter table t1 change v v2 varchar(32);
 
761
select * from t1;
 
762
v2
 
763
def
 
764
abc
 
765
hij
 
766
3r4f
 
767
alter table t1 change v2 v varchar(64);
 
768
select * from t1;
 
769
v
 
770
def
 
771
abc
 
772
hij
 
773
3r4f
 
774
update t1 set v = 'lmn' where v = 'hij';
 
775
select * from t1;
 
776
v
 
777
def
 
778
abc
 
779
3r4f
 
780
lmn
 
781
alter table t1 add i int auto_increment not null primary key first;
 
782
select * from t1;
 
783
i       v
 
784
1       def
 
785
2       abc
 
786
3       3r4f
 
787
4       lmn
 
788
update t1 set i=5 where i=3;
 
789
select * from t1;
 
790
i       v
 
791
1       def
 
792
2       abc
 
793
4       lmn
 
794
5       3r4f
 
795
alter table t1 change i i bigint;
 
796
select * from t1;
 
797
i       v
 
798
1       def
 
799
2       abc
 
800
4       lmn
 
801
5       3r4f
 
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');
 
804
i       v
 
805
4       lmn
 
806
drop table t1;
 
807
create table t1 (t varchar(255) default null, key t (t(80))) engine=myisam;
 
808
alter table t1 change t t text;
 
809
drop table t1;
 
810
CREATE TABLE t1 (s CHAR(8) BINARY);
 
811
INSERT INTO t1 VALUES ('test');
 
812
SELECT LENGTH(s) FROM t1;
 
813
LENGTH(s)
 
814
4
 
815
ALTER TABLE t1 MODIFY s CHAR(10) BINARY;
 
816
SELECT LENGTH(s) FROM t1;
 
817
LENGTH(s)
 
818
4
 
819
DROP TABLE t1;
 
820
CREATE TABLE t1 (s varbinary(8));
 
821
INSERT INTO t1 VALUES ('test');
 
822
SELECT LENGTH(s) FROM t1;
 
823
LENGTH(s)
 
824
4
 
825
SELECT HEX(s) FROM t1;
 
826
HEX(s)
 
827
74657374
 
828
ALTER TABLE t1 MODIFY s varbinary(10);
 
829
SELECT HEX(s) FROM t1;
 
830
HEX(s)
 
831
74657374
 
832
SELECT LENGTH(s) FROM t1;
 
833
LENGTH(s)
 
834
4
 
835
DROP TABLE t1;
 
836
CREATE TABLE t1 (v VARCHAR(3), b INT);
 
837
INSERT INTO t1 VALUES ('abc', 5);
 
838
SELECT * FROM t1;
 
839
v       b
 
840
abc     5
 
841
ALTER TABLE t1 MODIFY COLUMN v VARCHAR(4);
 
842
SELECT * FROM t1;
 
843
v       b
 
844
abc     5
 
845
DROP TABLE t1;
 
846
End of 5.0 tests
 
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 ();
 
855
select * from t1;
 
856
i
 
857
NULL
 
858
1
 
859
alter table t1 change i c char(10) default "Two";
 
860
insert into t1 values ();
 
861
select * from t1;
 
862
c
 
863
NULL
 
864
1
 
865
Two
 
866
alter table t1 modify c char(10) default "Three", rename to t2;
 
867
select * from t1;
 
868
ERROR HY000: Table 't1' was not locked with LOCK TABLES
 
869
select * from t2;
 
870
ERROR HY000: Table 't2' was not locked with LOCK TABLES
 
871
select * from t3;
 
872
j
 
873
NULL
 
874
unlock tables;
 
875
insert into t2 values ();
 
876
select * from t2;
 
877
c
 
878
NULL
 
879
1
 
880
Two
 
881
Three
 
882
lock table t2 write, t3 read;
 
883
alter table t2 change c vc varchar(100) default "Four", rename to t1;
 
884
select * from t1;
 
885
ERROR HY000: Table 't1' was not locked with LOCK TABLES
 
886
select * from t2;
 
887
ERROR HY000: Table 't2' was not locked with LOCK TABLES
 
888
select * from t3;
 
889
j
 
890
NULL
 
891
unlock tables;
 
892
insert into t1 values ();
 
893
select * from t1;
 
894
vc
 
895
NULL
 
896
1
 
897
Two
 
898
Three
 
899
Four
 
900
drop tables t1, t3;
 
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`;
 
914
Table   Create Table
 
915
tt+1    CREATE TEMPORARY TABLE `tt+1` (
 
916
  `c1` int
 
917
) ENGINE=PBXT
 
918
SHOW CREATE TABLE `tt+2`;
 
919
Table   Create Table
 
920
tt+2    CREATE TEMPORARY TABLE `tt+2` (
 
921
  `c1` int
 
922
) ENGINE=PBXT
 
923
DROP TABLE   `tt+1`, `tt+2`;
 
924
CREATE TEMPORARY TABLE `#sql1` (c1 INT);
 
925
CREATE TEMPORARY TABLE `@0023sql2` (c1 INT);
 
926
SHOW TABLES;
 
927
Tables_in_test
 
928
ALTER TABLE `#sql1`      RENAME `@0023sql1`;
 
929
ALTER TABLE `@0023sql2`  RENAME `#sql2`;
 
930
SHOW TABLES;
 
931
Tables_in_test
 
932
INSERT INTO `#sql2`      VALUES (1);
 
933
INSERT INTO `@0023sql1`  VALUES (2);
 
934
SHOW CREATE TABLE `#sql2`;
 
935
Table   Create Table
 
936
#sql2   CREATE TEMPORARY TABLE `#sql2` (
 
937
  `c1` int
 
938
) ENGINE=PBXT
 
939
SHOW CREATE TABLE `@0023sql1`;
 
940
Table   Create Table
 
941
@0023sql1       CREATE TEMPORARY TABLE `@0023sql1` (
 
942
  `c1` int
 
943
) ENGINE=PBXT
 
944
DROP TABLE `#sql2`, `@0023sql1`;
 
945
DROP TABLE IF EXISTS t1;
 
946
DROP TABLE IF EXISTS t2;
 
947
CREATE TABLE t1 (
 
948
int_field INTEGER NOT NULL,
 
949
char_field CHAR(10),
 
950
INDEX(`int_field`)
 
951
);
 
952
DESCRIBE t1;
 
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
 
966
1       edno
 
967
1       edno
 
968
2       dve
 
969
3       tri
 
970
5       pet
 
971
DESCRIBE t2;
 
972
Field   Type    Null    Key     Default Extra
 
973
unsigned_int_field      int     NO      MUL     NULL    
 
974
char_field      varchar(10)     YES             NULL    
 
975
DESCRIBE t2;
 
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;
 
980
DESCRIBE t2;
 
981
Field   Type    Null    Key     Default Extra
 
982
unsigned_int_field      bigint  NO      MUL     NULL    
 
983
char_field      varchar(10)     YES             NULL    
 
984
DROP TABLE t2;
 
985
CREATE TABLE t1 (f1 INT, f2 INT, f3 INT);
 
986
INSERT INTO t1 VALUES (1, 2, NULL);
 
987
SELECT * FROM t1;
 
988
f1      f2      f3
 
989
1       2       NULL
 
990
ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f1;
 
991
SELECT * FROM t1;
 
992
f1      f3      f2
 
993
1       NULL    2
 
994
ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f2;
 
995
SELECT * FROM t1;
 
996
f1      f2      f3
 
997
1       2       NULL
 
998
DROP TABLE t1;
 
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";
 
1003
unlock tables;
 
1004
select * from t1;
 
1005
c
 
1006
Two
 
1007
check table t1;
 
1008
Table   Op      Msg_type        Msg_text
 
1009
test.t1 check   status  OK
 
1010
drop table t1;