~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysql-test/r/alter_table.result

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
col5 enum('PENDING', 'ACTIVE', 'DISABLED') not null,
9
9
col6 int not null, to_be_deleted int);
10
10
insert into t1 values (2,4,3,5,"PENDING",1,7);
11
 
SELECT * FROM t1;
12
 
col1    col2    col3    col4    col5    col6    to_be_deleted
13
 
2       4       3       5       PENDING 1       7
14
11
alter table t1
15
12
add column col4_5 varchar(20) not null after col4,
16
13
add column col7 varchar(30) not null after col5,
17
 
add column col8 datetime not null default '1000-01-01 00:00:00', drop column to_be_deleted,
18
 
change column col2 fourth varchar(30) not null after col3,
19
 
modify column col6 int not null first;
20
 
ERROR HY000: Either a DEFAULt value or NULL NULL description is required for a new column if table is not empty
21
 
alter table t1
22
 
add column col4_5 varchar(20) DEFAULT "added" not null after col4,
23
 
add column col7 varchar(30) DEFAULT "added" not null after col5,
24
 
add column col8 datetime not null default '1000-01-01 00:00:00',
25
 
drop column to_be_deleted,
 
14
add column col8 datetime not null, drop column to_be_deleted,
26
15
change column col2 fourth varchar(30) not null after col3,
27
16
modify column col6 int not null first;
28
17
select * from t1;
29
18
col6    col1    col3    fourth  col4    col4_5  col5    col7    col8
30
 
1       2       3       4       5       added   PENDING added   1000-01-01 00:00:00
 
19
1       2       3       4       5               PENDING         0000-00-00 00:00:00
31
20
drop table t1;
32
 
create table t1 (bandID INT NOT NULL PRIMARY KEY, payoutID int NOT NULL);
 
21
create table t1 (bandID MEDIUMINT UNSIGNED NOT NULL PRIMARY KEY, payoutID SMALLINT UNSIGNED NOT NULL);
33
22
insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12);
34
 
alter table t1 add column new_col int;
 
23
alter table t1 add column new_col int, order by payoutid,bandid;
35
24
select * from t1;
36
25
bandID  payoutID        new_col
 
26
6       1       NULL
 
27
3       4       NULL
37
28
1       6       NULL
38
29
2       6       NULL
39
 
3       4       NULL
40
30
4       9       NULL
41
31
5       10      NULL
42
 
6       1       NULL
43
32
7       12      NULL
44
33
8       12      NULL
45
 
alter table t1;
 
34
alter table t1 order by bandid,payoutid;
46
35
select * from t1;
47
36
bandID  payoutID        new_col
48
37
1       6       NULL
55
44
8       12      NULL
56
45
drop table t1;
57
46
CREATE TABLE t1 (
58
 
GROUP_ID int DEFAULT '0' NOT NULL,
59
 
LANG_ID int DEFAULT '0' NOT NULL,
 
47
GROUP_ID int(10) unsigned DEFAULT '0' NOT NULL,
 
48
LANG_ID smallint(5) unsigned DEFAULT '0' NOT NULL,
60
49
NAME varchar(80) DEFAULT '' NOT NULL,
61
50
PRIMARY KEY (GROUP_ID,LANG_ID),
62
51
KEY NAME (NAME));
63
52
ALTER TABLE t1 CHANGE NAME NAME CHAR(80) not null;
64
 
show COLUMNS FROM t1;
65
 
Field   Type    Null    Default Default_is_NULL On_Update
66
 
GROUP_ID        INTEGER NO      0       NO      
67
 
LANG_ID INTEGER NO      0       NO      
68
 
NAME    VARCHAR NO              NO      
 
53
SHOW FULL COLUMNS FROM t1;
 
54
Field   Type    Collation       Null    Key     Default Extra   Privileges      Comment
 
55
GROUP_ID        int(10) unsigned        NULL    NO      PRI     0               #       
 
56
LANG_ID smallint(5) unsigned    NULL    NO      PRI     0               #       
 
57
NAME    char(80)        latin1_swedish_ci       NO      MUL     NULL            #       
69
58
DROP TABLE t1;
70
59
create table t1 (n int);
71
60
insert into t1 values(9),(3),(12),(10);
77
66
10
78
67
12
79
68
drop table t1;
80
 
CREATE TEMPORARY TABLE t1 (
81
 
id int NOT NULL default '0',
82
 
category_id int NOT NULL default '0',
83
 
type_id int NOT NULL default '0',
 
69
CREATE TABLE t1 (
 
70
id int(11) unsigned NOT NULL default '0',
 
71
category_id tinyint(4) unsigned NOT NULL default '0',
 
72
type_id tinyint(4) unsigned NOT NULL default '0',
84
73
body text NOT NULL,
85
 
user_id int NOT NULL default '0',
 
74
user_id int(11) unsigned NOT NULL default '0',
86
75
status enum('new','old') NOT NULL default 'new',
87
76
PRIMARY KEY (id)
88
77
) ENGINE=MyISAM;
89
78
ALTER TABLE t1 ORDER BY t1.id, t1.status, t1.type_id, t1.user_id, t1.body;
90
79
DROP TABLE t1;
91
 
create table t1 (i int not null auto_increment primary key);
 
80
CREATE TABLE t1 (AnamneseId int(10) unsigned 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 unsigned not null auto_increment primary key);
92
90
insert into t1 values (null),(null),(null),(null);
93
 
alter table t1 drop i,add i int not null auto_increment, drop primary key, add primary key (i);
 
91
alter table t1 drop i,add i int unsigned not null auto_increment, drop primary key, add primary key (i);
94
92
select * from t1;
95
93
i
96
94
1
110
108
name
111
109
mysqltest
112
110
alter table t1 rename mysqltest.t1;
113
 
ERROR 42S01: Table 'mysqltest.t1' already exists
 
111
ERROR 42S01: Table 't1' already exists
114
112
select * from t1;
115
113
name
116
114
current
125
123
key (n2, n3, n4, n1),
126
124
key (n3, n4, n1, n2),
127
125
key (n4, n1, n2, n3) );
128
 
alter table t1;
 
126
alter table t1 disable keys;
129
127
show keys from t1;
130
 
Table   Unique  Key_name        Seq_in_index    Column_name
131
 
t1      YES     n1      1       n1
132
 
t1      NO      n1_2    1       n1
133
 
t1      NO      n1_2    2       n2
134
 
t1      NO      n1_2    3       n3
135
 
t1      NO      n1_2    4       n4
136
 
t1      NO      n2      1       n2
137
 
t1      NO      n2      2       n3
138
 
t1      NO      n2      3       n4
139
 
t1      NO      n2      4       n1
140
 
t1      NO      n3      1       n3
141
 
t1      NO      n3      2       n4
142
 
t1      NO      n3      3       n1
143
 
t1      NO      n3      4       n2
144
 
t1      NO      n4      1       n4
145
 
t1      NO      n4      2       n1
146
 
t1      NO      n4      3       n2
147
 
t1      NO      n4      4       n3
148
 
set autocommit=0;
149
 
begin;
 
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      A       0       NULL    NULL            BTREE           
 
130
t1      1       n1_2    1       n1      A       NULL    NULL    NULL            BTREE   disabled        
 
131
t1      1       n1_2    2       n2      A       NULL    NULL    NULL    YES     BTREE   disabled        
 
132
t1      1       n1_2    3       n3      A       NULL    NULL    NULL    YES     BTREE   disabled        
 
133
t1      1       n1_2    4       n4      A       NULL    NULL    NULL    YES     BTREE   disabled        
 
134
t1      1       n2      1       n2      A       NULL    NULL    NULL    YES     BTREE   disabled        
 
135
t1      1       n2      2       n3      A       NULL    NULL    NULL    YES     BTREE   disabled        
 
136
t1      1       n2      3       n4      A       NULL    NULL    NULL    YES     BTREE   disabled        
 
137
t1      1       n2      4       n1      A       NULL    NULL    NULL            BTREE   disabled        
 
138
t1      1       n3      1       n3      A       NULL    NULL    NULL    YES     BTREE   disabled        
 
139
t1      1       n3      2       n4      A       NULL    NULL    NULL    YES     BTREE   disabled        
 
140
t1      1       n3      3       n1      A       NULL    NULL    NULL            BTREE   disabled        
 
141
t1      1       n3      4       n2      A       NULL    NULL    NULL    YES     BTREE   disabled        
 
142
t1      1       n4      1       n4      A       NULL    NULL    NULL    YES     BTREE   disabled        
 
143
t1      1       n4      2       n1      A       NULL    NULL    NULL            BTREE   disabled        
 
144
t1      1       n4      3       n2      A       NULL    NULL    NULL    YES     BTREE   disabled        
 
145
t1      1       n4      4       n3      A       NULL    NULL    NULL    YES     BTREE   disabled        
150
146
insert into t1 values(10,RAND()*1000,RAND()*1000,RAND());
151
147
insert into t1 values(9,RAND()*1000,RAND()*1000,RAND());
152
148
insert into t1 values(8,RAND()*1000,RAND()*1000,RAND());
157
153
insert into t1 values(3,RAND()*1000,RAND()*1000,RAND());
158
154
insert into t1 values(2,RAND()*1000,RAND()*1000,RAND());
159
155
insert into t1 values(1,RAND()*1000,RAND()*1000,RAND());
160
 
commit;
161
 
set autocommit=1;
162
156
alter table t1 enable keys;
163
 
Warnings:
164
 
Note    1031    Table storage engine for 't1' doesn't have this option
165
157
show keys from t1;
166
 
Table   Unique  Key_name        Seq_in_index    Column_name
167
 
t1      YES     n1      1       n1
168
 
t1      NO      n1_2    1       n1
169
 
t1      NO      n1_2    2       n2
170
 
t1      NO      n1_2    3       n3
171
 
t1      NO      n1_2    4       n4
172
 
t1      NO      n2      1       n2
173
 
t1      NO      n2      2       n3
174
 
t1      NO      n2      3       n4
175
 
t1      NO      n2      4       n1
176
 
t1      NO      n3      1       n3
177
 
t1      NO      n3      2       n4
178
 
t1      NO      n3      3       n1
179
 
t1      NO      n3      4       n2
180
 
t1      NO      n4      1       n4
181
 
t1      NO      n4      2       n1
182
 
t1      NO      n4      3       n2
183
 
t1      NO      n4      4       n3
 
158
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
159
t1      0       n1      1       n1      A       10      NULL    NULL            BTREE           
 
160
t1      1       n1_2    1       n1      A       10      NULL    NULL            BTREE           
 
161
t1      1       n1_2    2       n2      A       10      NULL    NULL    YES     BTREE           
 
162
t1      1       n1_2    3       n3      A       10      NULL    NULL    YES     BTREE           
 
163
t1      1       n1_2    4       n4      A       10      NULL    NULL    YES     BTREE           
 
164
t1      1       n2      1       n2      A       10      NULL    NULL    YES     BTREE           
 
165
t1      1       n2      2       n3      A       10      NULL    NULL    YES     BTREE           
 
166
t1      1       n2      3       n4      A       10      NULL    NULL    YES     BTREE           
 
167
t1      1       n2      4       n1      A       10      NULL    NULL            BTREE           
 
168
t1      1       n3      1       n3      A       10      NULL    NULL    YES     BTREE           
 
169
t1      1       n3      2       n4      A       10      NULL    NULL    YES     BTREE           
 
170
t1      1       n3      3       n1      A       10      NULL    NULL            BTREE           
 
171
t1      1       n3      4       n2      A       10      NULL    NULL    YES     BTREE           
 
172
t1      1       n4      1       n4      A       10      NULL    NULL    YES     BTREE           
 
173
t1      1       n4      2       n1      A       10      NULL    NULL            BTREE           
 
174
t1      1       n4      3       n2      A       10      NULL    NULL    YES     BTREE           
 
175
t1      1       n4      4       n3      A       10      NULL    NULL    YES     BTREE           
184
176
drop table t1;
185
 
create table t1 (i int not null auto_increment primary key);
 
177
create table t1 (i int unsigned not null auto_increment primary key);
186
178
alter table t1 rename t2;
187
179
alter table t2 rename t1, add c char(10) comment "no comment";
188
180
show columns from t1;
189
 
Field   Type    Null    Default Default_is_NULL On_Update
190
 
i       INTEGER NO              NO      
191
 
c       VARCHAR YES             YES     
 
181
Field   Type    Null    Key     Default Extra
 
182
i       int(10) unsigned        NO      PRI     NULL    auto_increment
 
183
c       char(10)        YES             NULL    
192
184
drop table t1;
193
185
create table t1 (a int, b int);
194
 
set autocommit=0;
195
 
begin;
196
186
insert into t1 values(1,100), (2,100), (3, 100);
197
187
insert into t1 values(1,99), (2,99), (3, 99);
198
188
insert into t1 values(1,98), (2,98), (3, 98);
293
283
insert into t1 values(1,3), (2,3), (3, 3);
294
284
insert into t1 values(1,2), (2,2), (3, 2);
295
285
insert into t1 values(1,1), (2,1), (3, 1);
296
 
commit;
297
 
set autocommit=1;
298
286
alter table t1 add unique (a,b), add key (b);
299
287
show keys from t1;
300
 
Table   Unique  Key_name        Seq_in_index    Column_name
301
 
t1      YES     a       1       a
302
 
t1      YES     a       2       b
303
 
t1      NO      b       1       b
 
288
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
289
t1      0       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
 
290
t1      0       a       2       b       A       NULL    NULL    NULL    YES     BTREE           
 
291
t1      1       b       1       b       A       100     NULL    NULL    YES     BTREE           
304
292
analyze table t1;
305
293
Table   Op      Msg_type        Msg_text
306
294
test.t1 analyze status  OK
307
295
show keys from t1;
308
 
Table   Unique  Key_name        Seq_in_index    Column_name
309
 
t1      YES     a       1       a
310
 
t1      YES     a       2       b
311
 
t1      NO      b       1       b
312
 
drop table t1;
313
 
CREATE TEMPORARY TABLE t1 (
314
 
Host varchar(16) NOT NULL default '',
315
 
User varchar(16) NOT NULL default '',
 
296
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
297
t1      0       a       1       a       A       3       NULL    NULL    YES     BTREE           
 
298
t1      0       a       2       b       A       300     NULL    NULL    YES     BTREE           
 
299
t1      1       b       1       b       A       100     NULL    NULL    YES     BTREE           
 
300
drop table t1;
 
301
CREATE TABLE t1 (i int(10), index(i) );
 
302
ALTER TABLE t1 DISABLE KEYS;
 
303
INSERT DELAYED INTO t1 VALUES(1),(2),(3);
 
304
ALTER TABLE t1 ENABLE KEYS;
 
305
drop table t1;
 
306
CREATE TABLE t1 (
 
307
Host varchar(16) binary NOT NULL default '',
 
308
User varchar(16) binary NOT NULL default '',
 
309
PRIMARY KEY  (Host,User)
 
310
) ENGINE=MyISAM;
 
311
ALTER TABLE t1 DISABLE KEYS;
 
312
LOCK TABLES t1 WRITE;
 
313
INSERT INTO t1 VALUES ('localhost','root'),('localhost',''),('games','monty');
 
314
SHOW INDEX FROM t1;
 
315
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
316
t1      0       PRIMARY 1       Host    A       NULL    NULL    NULL            BTREE           
 
317
t1      0       PRIMARY 2       User    A       0       NULL    NULL            BTREE           
 
318
ALTER TABLE t1 ENABLE KEYS;
 
319
UNLOCK TABLES;
 
320
CHECK TABLES t1;
 
321
Table   Op      Msg_type        Msg_text
 
322
test.t1 check   status  OK
 
323
DROP TABLE t1;
 
324
CREATE TABLE t1 (
 
325
Host varchar(16) binary NOT NULL default '',
 
326
User varchar(16) binary NOT NULL default '',
316
327
PRIMARY KEY  (Host,User),
317
328
KEY  (Host)
318
329
) ENGINE=MyISAM;
319
330
ALTER TABLE t1 DISABLE KEYS;
 
331
SHOW INDEX FROM t1;
 
332
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
333
t1      0       PRIMARY 1       Host    A       NULL    NULL    NULL            BTREE           
 
334
t1      0       PRIMARY 2       User    A       0       NULL    NULL            BTREE           
 
335
t1      1       Host    1       Host    A       NULL    NULL    NULL            BTREE   disabled        
 
336
LOCK TABLES t1 WRITE;
320
337
INSERT INTO t1 VALUES ('localhost','root'),('localhost','');
 
338
SHOW INDEX FROM t1;
 
339
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
340
t1      0       PRIMARY 1       Host    A       NULL    NULL    NULL            BTREE           
 
341
t1      0       PRIMARY 2       User    A       0       NULL    NULL            BTREE           
 
342
t1      1       Host    1       Host    A       NULL    NULL    NULL            BTREE   disabled        
321
343
ALTER TABLE t1 ENABLE KEYS;
 
344
SHOW INDEX FROM t1;
 
345
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
346
t1      0       PRIMARY 1       Host    A       NULL    NULL    NULL            BTREE           
 
347
t1      0       PRIMARY 2       User    A       2       NULL    NULL            BTREE           
 
348
t1      1       Host    1       Host    A       1       NULL    NULL            BTREE           
 
349
UNLOCK TABLES;
322
350
CHECK TABLES t1;
323
351
Table   Op      Msg_type        Msg_text
324
352
test.t1 check   status  OK
 
353
LOCK TABLES t1 WRITE;
325
354
ALTER TABLE t1 RENAME t2;
 
355
UNLOCK TABLES;
326
356
select * from t2;
327
357
Host    User
328
358
localhost       
329
359
localhost       root
330
360
DROP TABLE t2;
 
361
CREATE TABLE t1 (
 
362
Host varchar(16) binary NOT NULL default '',
 
363
User varchar(16) binary NOT NULL default '',
 
364
PRIMARY KEY  (Host,User),
 
365
KEY  (Host)
 
366
) ENGINE=MyISAM;
 
367
LOCK TABLES t1 WRITE;
 
368
ALTER TABLE t1 DISABLE KEYS;
 
369
SHOW INDEX FROM t1;
 
370
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
371
t1      0       PRIMARY 1       Host    A       NULL    NULL    NULL            BTREE           
 
372
t1      0       PRIMARY 2       User    A       0       NULL    NULL            BTREE           
 
373
t1      1       Host    1       Host    A       NULL    NULL    NULL            BTREE   disabled        
 
374
DROP TABLE t1;
331
375
create table t1 (a int);
332
376
alter table t1 rename to ``;
333
377
ERROR 42000: Incorrect table name ''
337
381
drop table if exists t1;
338
382
Warnings:
339
383
Note    1051    Unknown table 't1'
340
 
create TEMPORARY table t1 ( a varchar(10) not null primary key ) engine=myisam;
 
384
create table t1 ( a varchar(10) not null primary key ) engine=myisam;
341
385
flush tables;
342
386
alter table t1 modify a varchar(10);
343
387
flush tables;
344
388
alter table t1 modify a varchar(10) not null;
345
389
drop table if exists t1;
346
 
create TEMPORARY 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;
347
 
insert into t1 (a,b,c,d,e,f,g,h,i) values(1,1,1,1,1,1,1,1,1);
 
390
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;
 
391
insert into t1 (a) values(1);
348
392
show table status like 't1';
349
 
Session Schema  Name    Type    Engine  Version Rows    Avg_row_length  Table_size      Auto_increment
350
 
#       test    t1      TEMPORARY       MyISAM  #       #       #       #       #
 
393
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
 
394
t1      MyISAM  10      Fixed   1       37      X       X       X       X       X       X       X       X       latin1_swedish_ci       NULL            
351
395
alter table t1 modify a int;
352
396
show table status like 't1';
353
 
Session Schema  Name    Type    Engine  Version Rows    Avg_row_length  Table_size      Auto_increment
354
 
#       test    t1      TEMPORARY       MyISAM  #       #       #       #       #
 
397
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
 
398
t1      MyISAM  10      Fixed   1       37      X       X       X       X       X       X       X       X       latin1_swedish_ci       NULL            
355
399
drop table t1;
356
 
create TEMPORARY 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;
 
400
create table t1 (a int not null, b int not null, c int not null, d int not null, e int not null, f int not null, g int not null, h int not null,i int not null, primary key (a,b,c,d,e,f,g,i,h)) engine=MyISAM;
357
401
insert into t1 (a) values(1);
 
402
Warnings:
 
403
Warning 1364    Field 'b' doesn't have a default value
 
404
Warning 1364    Field 'c' doesn't have a default value
 
405
Warning 1364    Field 'd' doesn't have a default value
 
406
Warning 1364    Field 'e' doesn't have a default value
 
407
Warning 1364    Field 'f' doesn't have a default value
 
408
Warning 1364    Field 'g' doesn't have a default value
 
409
Warning 1364    Field 'h' doesn't have a default value
 
410
Warning 1364    Field 'i' doesn't have a default value
358
411
show table status like 't1';
359
 
Session Schema  Name    Type    Engine  Version Rows    Avg_row_length  Table_size      Auto_increment
360
 
#       test    t1      TEMPORARY       MyISAM  #       #       #       #       #
 
412
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
 
413
t1      MyISAM  10      Fixed   1       37      X       X       X       X       X       X       X       X       latin1_swedish_ci       NULL            
 
414
drop table t1;
 
415
set names koi8r;
 
416
create table t1 (a char(10) character set koi8r);
 
417
insert into t1 values ('����');
 
418
select a,hex(a) from t1;
 
419
a       hex(a)
 
420
����    D4C5D3D4
 
421
alter table t1 change a a char(10) character set cp1251;
 
422
select a,hex(a) from t1;
 
423
a       hex(a)
 
424
����    F2E5F1F2
 
425
alter table t1 change a a binary(4);
 
426
select a,hex(a) from t1;
 
427
a       hex(a)
 
428
����    F2E5F1F2
 
429
alter table t1 change a a char(10) character set cp1251;
 
430
select a,hex(a) from t1;
 
431
a       hex(a)
 
432
����    F2E5F1F2
 
433
alter table t1 change a a char(10) character set koi8r;
 
434
select a,hex(a) from t1;
 
435
a       hex(a)
 
436
����    D4C5D3D4
 
437
alter table t1 change a a varchar(10) character set cp1251;
 
438
select a,hex(a) from t1;
 
439
a       hex(a)
 
440
����    F2E5F1F2
 
441
alter table t1 change a a char(10) character set koi8r;
 
442
select a,hex(a) from t1;
 
443
a       hex(a)
 
444
����    D4C5D3D4
 
445
alter table t1 change a a text character set cp1251;
 
446
select a,hex(a) from t1;
 
447
a       hex(a)
 
448
����    F2E5F1F2
 
449
alter table t1 change a a char(10) character set koi8r;
 
450
select a,hex(a) from t1;
 
451
a       hex(a)
 
452
����    D4C5D3D4
 
453
delete from t1;
 
454
show create table t1;
 
455
Table   Create Table
 
456
t1      CREATE TABLE `t1` (
 
457
  `a` char(10) CHARACTER SET koi8r DEFAULT NULL
 
458
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
459
alter table t1 DEFAULT CHARACTER SET latin1;
 
460
show create table t1;
 
461
Table   Create Table
 
462
t1      CREATE TABLE `t1` (
 
463
  `a` char(10) CHARACTER SET koi8r DEFAULT NULL
 
464
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
465
alter table t1 CONVERT TO CHARACTER SET latin1;
 
466
show create table t1;
 
467
Table   Create Table
 
468
t1      CREATE TABLE `t1` (
 
469
  `a` char(10) DEFAULT NULL
 
470
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
471
alter table t1 DEFAULT CHARACTER SET cp1251;
 
472
show create table t1;
 
473
Table   Create Table
 
474
t1      CREATE TABLE `t1` (
 
475
  `a` char(10) CHARACTER SET latin1 DEFAULT NULL
 
476
) ENGINE=MyISAM DEFAULT CHARSET=cp1251
 
477
drop table t1;
 
478
create table t1 (myblob longblob,mytext longtext) 
 
479
default charset latin1 collate latin1_general_cs;
 
480
show create table t1;
 
481
Table   Create Table
 
482
t1      CREATE TABLE `t1` (
 
483
  `myblob` longblob,
 
484
  `mytext` longtext COLLATE latin1_general_cs
 
485
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs
 
486
alter table t1 character set latin2;
 
487
show create table t1;
 
488
Table   Create Table
 
489
t1      CREATE TABLE `t1` (
 
490
  `myblob` longblob,
 
491
  `mytext` longtext CHARACTER SET latin1 COLLATE latin1_general_cs
 
492
) ENGINE=MyISAM DEFAULT CHARSET=latin2
361
493
drop table t1;
362
494
CREATE TABLE t1 (a int PRIMARY KEY, b INT UNIQUE);
363
495
ALTER TABLE t1 DROP PRIMARY KEY;
364
496
SHOW CREATE TABLE t1;
365
497
Table   Create Table
366
498
t1      CREATE TABLE `t1` (
367
 
  `a` INT NOT NULL,
368
 
  `b` INT DEFAULT NULL,
 
499
  `a` int(11) NOT NULL,
 
500
  `b` int(11) DEFAULT NULL,
369
501
  UNIQUE KEY `b` (`b`)
370
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
502
) ENGINE=MyISAM DEFAULT CHARSET=latin1
371
503
ALTER TABLE t1 DROP PRIMARY KEY;
372
504
ERROR 42000: Can't DROP 'PRIMARY'; check that column/key exists
373
505
DROP TABLE t1;
377
509
ERROR 42000: Can't DROP 'no_such_key'; check that column/key exists
378
510
alter table t1 drop key a;
379
511
drop table t1;
380
 
CREATE TEMPORARY TABLE T12207(a int) ENGINE=MYISAM;
 
512
CREATE TABLE T12207(a int) ENGINE=MYISAM;
381
513
ALTER TABLE T12207 DISCARD TABLESPACE;
382
514
ERROR HY000: Table storage engine for 'T12207' doesn't have this option
383
515
DROP TABLE T12207;
 
516
create table t1 (a text) character set koi8r;
 
517
insert into t1 values (_koi8r'����');
 
518
select hex(a) from t1;
 
519
hex(a)
 
520
D4C5D3D4
 
521
alter table t1 convert to character set cp1251;
 
522
select hex(a) from t1;
 
523
hex(a)
 
524
F2E5F1F2
 
525
drop table t1;
384
526
create table t1 ( a timestamp );
385
527
alter table t1 add unique ( a(1) );
386
528
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
388
530
drop table if exists t1;
389
531
create table t1 (a int, key(a));
390
532
show indexes from t1;
391
 
Table   Unique  Key_name        Seq_in_index    Column_name
392
 
t1      NO      a       1       a
 
533
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
534
t1      1       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
393
535
"this used not to disable the index"
394
 
alter table t1 modify a int;
395
 
show indexes from t1;
396
 
Table   Unique  Key_name        Seq_in_index    Column_name
397
 
t1      NO      a       1       a
398
 
alter table t1 enable keys;
399
 
Warnings:
400
 
Note    1031    Table storage engine for 't1' doesn't have this option
401
 
show indexes from t1;
402
 
Table   Unique  Key_name        Seq_in_index    Column_name
403
 
t1      NO      a       1       a
404
 
alter table t1 modify a bigint;
405
 
show indexes from t1;
406
 
Table   Unique  Key_name        Seq_in_index    Column_name
407
 
t1      NO      a       1       a
408
 
alter table t1 enable keys;
409
 
Warnings:
410
 
Note    1031    Table storage engine for 't1' doesn't have this option
411
 
show indexes from t1;
412
 
Table   Unique  Key_name        Seq_in_index    Column_name
413
 
t1      NO      a       1       a
414
 
alter table t1 add b char(10);
415
 
show indexes from t1;
416
 
Table   Unique  Key_name        Seq_in_index    Column_name
417
 
t1      NO      a       1       a
418
 
alter table t1 add c decimal(10,2);
419
 
show indexes from t1;
420
 
Table   Unique  Key_name        Seq_in_index    Column_name
421
 
t1      NO      a       1       a
 
536
alter table t1 modify a int, disable keys;
 
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      1       a       1       a       A       NULL    NULL    NULL    YES     BTREE   disabled        
 
540
alter table t1 enable keys;
 
541
show indexes from t1;
 
542
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
543
t1      1       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
 
544
alter table t1 modify a bigint, disable keys;
 
545
show indexes from t1;
 
546
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
547
t1      1       a       1       a       A       NULL    NULL    NULL    YES     BTREE   disabled        
 
548
alter table t1 enable keys;
 
549
show indexes from t1;
 
550
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
551
t1      1       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
 
552
alter table t1 add b char(10), disable keys;
 
553
show indexes from t1;
 
554
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
555
t1      1       a       1       a       A       NULL    NULL    NULL    YES     BTREE   disabled        
 
556
alter table t1 add c decimal(10,2), enable keys;
 
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      1       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
422
560
"this however did"
423
 
alter table t1;
 
561
alter table t1 disable keys;
424
562
show indexes from t1;
425
 
Table   Unique  Key_name        Seq_in_index    Column_name
426
 
t1      NO      a       1       a
 
563
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
564
t1      1       a       1       a       A       NULL    NULL    NULL    YES     BTREE   disabled        
427
565
desc t1;
428
 
Field   Type    Null    Default Default_is_NULL On_Update
429
 
a       BIGINT  YES             YES     
430
 
b       VARCHAR YES             YES     
431
 
c       DECIMAL YES             YES     
 
566
Field   Type    Null    Key     Default Extra
 
567
a       bigint(20)      YES     MUL     NULL    
 
568
b       char(10)        YES             NULL    
 
569
c       decimal(10,2)   YES             NULL    
432
570
alter table t1 add d decimal(15,5);
433
571
"The key should still be disabled"
434
572
show indexes from t1;
435
 
Table   Unique  Key_name        Seq_in_index    Column_name
436
 
t1      NO      a       1       a
 
573
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
574
t1      1       a       1       a       A       NULL    NULL    NULL    YES     BTREE   disabled        
437
575
drop table t1;
438
576
"Now will test with one unique index"
439
577
create table t1(a int, b char(10), unique(a));
440
578
show indexes from t1;
441
 
Table   Unique  Key_name        Seq_in_index    Column_name
442
 
t1      YES     a       1       a
443
 
alter table t1;
 
579
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
580
t1      0       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
 
581
alter table t1 disable keys;
444
582
show indexes from t1;
445
 
Table   Unique  Key_name        Seq_in_index    Column_name
446
 
t1      YES     a       1       a
 
583
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
584
t1      0       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
447
585
alter table t1 enable keys;
448
 
Warnings:
449
 
Note    1031    Table storage engine for 't1' doesn't have this option
450
586
"If no copy on noop change, this won't touch the data file"
451
587
"Unique index, no change"
452
 
alter table t1 modify a int;
 
588
alter table t1 modify a int, disable keys;
453
589
show indexes from t1;
454
 
Table   Unique  Key_name        Seq_in_index    Column_name
455
 
t1      YES     a       1       a
 
590
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
591
t1      0       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
456
592
"Change the type implying data copy"
457
593
"Unique index, no change"
458
 
alter table t1 modify a bigint;
459
 
show indexes from t1;
460
 
Table   Unique  Key_name        Seq_in_index    Column_name
461
 
t1      YES     a       1       a
462
 
alter table t1 modify a bigint;
463
 
show indexes from t1;
464
 
Table   Unique  Key_name        Seq_in_index    Column_name
465
 
t1      YES     a       1       a
 
594
alter table t1 modify a bigint, disable keys;
 
595
show indexes from t1;
 
596
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
597
t1      0       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
 
598
alter table t1 modify a bigint;
 
599
show indexes from t1;
 
600
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
601
t1      0       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
466
602
alter table t1 modify a int;
467
603
show indexes from t1;
468
 
Table   Unique  Key_name        Seq_in_index    Column_name
469
 
t1      YES     a       1       a
 
604
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
605
t1      0       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
470
606
drop table t1;
471
607
"Now will test with one unique and one non-unique index"
472
608
create table t1(a int, b char(10), unique(a), key(b));
473
609
show indexes from t1;
474
 
Table   Unique  Key_name        Seq_in_index    Column_name
475
 
t1      YES     a       1       a
476
 
t1      NO      b       1       b
477
 
alter table t1;
 
610
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
611
t1      0       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
 
612
t1      1       b       1       b       A       NULL    NULL    NULL    YES     BTREE           
 
613
alter table t1 disable keys;
478
614
show indexes from t1;
479
 
Table   Unique  Key_name        Seq_in_index    Column_name
480
 
t1      YES     a       1       a
481
 
t1      NO      b       1       b
 
615
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
616
t1      0       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
 
617
t1      1       b       1       b       A       NULL    NULL    NULL    YES     BTREE   disabled        
482
618
alter table t1 enable keys;
483
 
Warnings:
484
 
Note    1031    Table storage engine for 't1' doesn't have this option
485
619
"If no copy on noop change, this won't touch the data file"
486
620
"The non-unique index will be disabled"
487
 
alter table t1 modify a int;
 
621
alter table t1 modify a int, disable keys;
488
622
show indexes from t1;
489
 
Table   Unique  Key_name        Seq_in_index    Column_name
490
 
t1      YES     a       1       a
491
 
t1      NO      b       1       b
 
623
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
624
t1      0       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
 
625
t1      1       b       1       b       A       NULL    NULL    NULL    YES     BTREE   disabled        
492
626
alter table t1 enable keys;
493
 
Warnings:
494
 
Note    1031    Table storage engine for 't1' doesn't have this option
495
627
show indexes from t1;
496
 
Table   Unique  Key_name        Seq_in_index    Column_name
497
 
t1      YES     a       1       a
498
 
t1      NO      b       1       b
 
628
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
629
t1      0       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
 
630
t1      1       b       1       b       A       NULL    NULL    NULL    YES     BTREE           
499
631
"Change the type implying data copy"
500
632
"The non-unique index will be disabled"
501
 
alter table t1 modify a bigint;
 
633
alter table t1 modify a bigint, disable keys;
502
634
show indexes from t1;
503
 
Table   Unique  Key_name        Seq_in_index    Column_name
504
 
t1      YES     a       1       a
505
 
t1      NO      b       1       b
 
635
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
636
t1      0       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
 
637
t1      1       b       1       b       A       NULL    NULL    NULL    YES     BTREE   disabled        
506
638
"Change again the type, but leave the indexes as_is"
507
639
alter table t1 modify a int;
508
640
show indexes from t1;
509
 
Table   Unique  Key_name        Seq_in_index    Column_name
510
 
t1      YES     a       1       a
511
 
t1      NO      b       1       b
 
641
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
642
t1      0       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
 
643
t1      1       b       1       b       A       NULL    NULL    NULL    YES     BTREE   disabled        
512
644
"Try the same. When data is no copied on similar tables, this is noop"
513
645
alter table t1 modify a int;
514
646
show indexes from t1;
515
 
Table   Unique  Key_name        Seq_in_index    Column_name
516
 
t1      YES     a       1       a
517
 
t1      NO      b       1       b
 
647
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
648
t1      0       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
 
649
t1      1       b       1       b       A       NULL    NULL    NULL    YES     BTREE   disabled        
518
650
drop table t1;
519
651
create database mysqltest;
520
652
create table t1 (c1 int);
527
659
use mysqltest;
528
660
drop database mysqltest;
529
661
alter table test.t1 rename t1;
530
 
ERROR 3D000: No schema selected
 
662
ERROR 3D000: No database selected
531
663
alter table test.t1 rename test.t1;
532
664
use test;
533
665
drop table t1;
534
 
CREATE TABLE t1(a INT) ROW_FORMAT=COMPACT;
 
666
CREATE TABLE t1(a INT) ROW_FORMAT=FIXED;
535
667
CREATE INDEX i1 ON t1(a);
536
668
SHOW CREATE TABLE t1;
537
669
Table   Create Table
538
670
t1      CREATE TABLE `t1` (
539
 
  `a` INT DEFAULT NULL,
 
671
  `a` int(11) DEFAULT NULL,
540
672
  KEY `i1` (`a`)
541
 
) ENGINE=DEFAULT ROW_FORMAT='COMPACT' COLLATE = utf8_general_ci
 
673
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=FIXED
542
674
DROP INDEX i1 ON t1;
543
675
SHOW CREATE TABLE t1;
544
676
Table   Create Table
545
677
t1      CREATE TABLE `t1` (
546
 
  `a` INT DEFAULT NULL
547
 
) ENGINE=DEFAULT ROW_FORMAT='COMPACT' COLLATE = utf8_general_ci
 
678
  `a` int(11) DEFAULT NULL
 
679
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=FIXED
548
680
DROP TABLE t1;
549
681
DROP TABLE IF EXISTS bug24219;
550
682
DROP TABLE IF EXISTS bug24219_2;
551
683
CREATE TABLE bug24219 (a INT, INDEX(a));
552
684
SHOW INDEX FROM bug24219;
553
 
Table   Unique  Key_name        Seq_in_index    Column_name
554
 
bug24219        NO      a       1       a
 
685
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
686
bug24219        1       a       1       a       A       NULL    NULL    NULL    YES     BTREE           
555
687
ALTER TABLE bug24219 RENAME TO bug24219_2, DISABLE KEYS;
556
 
Warnings:
557
 
Note    1031    Table storage engine for 'bug24219' doesn't have this option
558
688
SHOW INDEX FROM bug24219_2;
559
 
Table   Unique  Key_name        Seq_in_index    Column_name
560
 
bug24219_2      NO      a       1       a
 
689
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
690
bug24219_2      1       a       1       a       A       NULL    NULL    NULL    YES     BTREE   disabled        
561
691
DROP TABLE bug24219_2;
562
692
drop table if exists table_24562;
563
693
create table table_24562(
662
792
3       3       Stored Functions        You
663
793
2       3       Server  Me
664
794
alter table table_24562 order by 12;
665
 
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near '12' at line 1
 
795
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
666
796
alter table table_24562 order by (section + 12);
667
 
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near '(section + 12)' at line 1
 
797
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
668
798
alter table table_24562 order by length(title);
669
 
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near '(title)' at line 1
 
799
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
 
800
alter table table_24562 order by (select 12 from dual);
 
801
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 '(select 12 from dual)' at line 1
670
802
alter table table_24562 order by no_such_col;
671
803
ERROR 42S22: Unknown column 'no_such_col' in 'order clause'
672
804
drop table table_24562;
673
 
create table t1 (mycol int not null);
 
805
create table t1 (mycol int(10) not null);
674
806
alter table t1 alter column mycol set default 0;
675
807
desc t1;
676
 
Field   Type    Null    Default Default_is_NULL On_Update
677
 
mycol   INTEGER NO      0       NO      
 
808
Field   Type    Null    Key     Default Extra
 
809
mycol   int(10) NO              0       
678
810
drop table t1;
679
 
create TEMPORARY table t1(id int primary key auto_increment) engine=MEMORY;
 
811
create table t1(id int(8) primary key auto_increment) engine=heap;
680
812
insert into t1 values (null);
681
813
insert into t1 values (null);
682
814
select * from t1;
691
823
1
692
824
2
693
825
50
694
 
alter table t1 engine = MEMORY;
 
826
alter table t1 engine = heap;
695
827
insert into t1 values (null);
696
828
select * from t1;
697
829
id
700
832
50
701
833
51
702
834
drop table t1;
 
835
set @orig_sql_mode = @@sql_mode;
 
836
set sql_mode="no_zero_date";
 
837
create table t1(f1 int);
 
838
alter table t1 add column f2 datetime not null, add column f21 date not null;
 
839
insert into t1 values(1,'2000-01-01','2000-01-01');
 
840
alter table t1 add column f3 datetime not null;
 
841
ERROR 22007: Incorrect datetime value: '0000-00-00 00:00:00' for column 'f3' at row 1
 
842
alter table t1 add column f3 date not null;
 
843
ERROR 22007: Incorrect date value: '0000-00-00' for column 'f3' at row 1
 
844
alter table t1 add column f4 datetime not null default '2002-02-02',
 
845
add column f41 date not null;
 
846
ERROR 22007: Incorrect date value: '0000-00-00' for column 'f41' at row 1
 
847
alter table t1 add column f4 datetime not null default '2002-02-02',
 
848
add column f41 date not null default '2002-02-02';
 
849
select * from t1;
 
850
f1      f2      f21     f4      f41
 
851
1       2000-01-01 00:00:00     2000-01-01      2002-02-02 00:00:00     2002-02-02
 
852
drop table t1;
 
853
set sql_mode= @orig_sql_mode;
703
854
create table t1 (v varchar(32));
704
855
insert into t1 values ('def'),('abc'),('hij'),('3r4f');
705
856
select * from t1;
741
892
i       v
742
893
1       def
743
894
2       abc
 
895
5       lmn
744
896
4       3r4f
745
 
5       lmn
746
897
alter table t1 change i i bigint;
747
898
select * from t1;
748
899
i       v
749
900
1       def
750
901
2       abc
 
902
5       lmn
751
903
4       3r4f
752
 
5       lmn
753
904
alter table t1 add unique key (i, v);
754
905
select * from t1 where i between 2 and 4 and v in ('def','3r4f','lmn');
755
906
i       v
756
907
4       3r4f
757
908
drop table t1;
758
 
create TEMPORARY table t1 (t varchar(255) default null, key t (t(80))) engine=myisam;
 
909
create table t1 (t varchar(255) default null, key t (t(80)))
 
910
engine=myisam default charset=latin1;
759
911
alter table t1 change t t text;
760
912
drop table t1;
761
 
CREATE TABLE t1 (s CHAR(8));
762
 
INSERT INTO t1 VALUES ('test');
763
 
SELECT LENGTH(s) FROM t1;
764
 
LENGTH(s)
765
 
4
766
 
ALTER TABLE t1 MODIFY s CHAR(10);
767
 
SELECT LENGTH(s) FROM t1;
768
 
LENGTH(s)
769
 
4
770
 
DROP TABLE t1;
771
 
CREATE TABLE t1 (s varbinary(8));
772
 
INSERT INTO t1 VALUES ('test');
773
 
SELECT LENGTH(s) FROM t1;
774
 
LENGTH(s)
775
 
4
776
 
SELECT HEX(s) FROM t1;
777
 
HEX(s)
778
 
74657374
779
 
ALTER TABLE t1 MODIFY s varbinary(10);
780
 
SELECT HEX(s) FROM t1;
781
 
HEX(s)
782
 
74657374
783
 
SELECT LENGTH(s) FROM t1;
784
 
LENGTH(s)
785
 
4
 
913
CREATE TABLE t1 (a varchar(500));
 
914
ALTER TABLE t1 ADD b GEOMETRY NOT NULL, ADD SPATIAL INDEX(b);
 
915
SHOW CREATE TABLE t1;
 
916
Table   Create Table
 
917
t1      CREATE TABLE `t1` (
 
918
  `a` varchar(500) DEFAULT NULL,
 
919
  `b` geometry NOT NULL,
 
920
  SPATIAL KEY `b` (`b`)
 
921
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
922
ALTER TABLE t1 ADD KEY(b(50));
 
923
SHOW CREATE TABLE t1;
 
924
Table   Create Table
 
925
t1      CREATE TABLE `t1` (
 
926
  `a` varchar(500) DEFAULT NULL,
 
927
  `b` geometry NOT NULL,
 
928
  SPATIAL KEY `b` (`b`),
 
929
  KEY `b_2` (`b`(50))
 
930
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
931
ALTER TABLE t1 ADD c POINT;
 
932
SHOW CREATE TABLE t1;
 
933
Table   Create Table
 
934
t1      CREATE TABLE `t1` (
 
935
  `a` varchar(500) DEFAULT NULL,
 
936
  `b` geometry NOT NULL,
 
937
  `c` point DEFAULT NULL,
 
938
  SPATIAL KEY `b` (`b`),
 
939
  KEY `b_2` (`b`(50))
 
940
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
941
CREATE TABLE t2 (a INT, KEY (a(20)));
 
942
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
 
943
ALTER TABLE t1 ADD d INT;
 
944
ALTER TABLE t1 ADD KEY (d(20));
 
945
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
 
946
ALTER TABLE t1 ADD e GEOMETRY NOT NULL, ADD SPATIAL KEY (e(30));
 
947
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
 
948
DROP TABLE t1;
 
949
CREATE TABLE t1 (s CHAR(8) BINARY);
 
950
INSERT INTO t1 VALUES ('test');
 
951
SELECT LENGTH(s) FROM t1;
 
952
LENGTH(s)
 
953
4
 
954
ALTER TABLE t1 MODIFY s CHAR(10) BINARY;
 
955
SELECT LENGTH(s) FROM t1;
 
956
LENGTH(s)
 
957
4
 
958
DROP TABLE t1;
 
959
CREATE TABLE t1 (s BINARY(8));
 
960
INSERT INTO t1 VALUES ('test');
 
961
SELECT LENGTH(s) FROM t1;
 
962
LENGTH(s)
 
963
8
 
964
SELECT HEX(s) FROM t1;
 
965
HEX(s)
 
966
7465737400000000
 
967
ALTER TABLE t1 MODIFY s BINARY(10);
 
968
SELECT HEX(s) FROM t1;
 
969
HEX(s)
 
970
74657374000000000000
 
971
SELECT LENGTH(s) FROM t1;
 
972
LENGTH(s)
 
973
10
786
974
DROP TABLE t1;
787
975
CREATE TABLE t1 (v VARCHAR(3), b INT);
788
976
INSERT INTO t1 VALUES ('abc', 5);
795
983
abc     5
796
984
DROP TABLE t1;
797
985
End of 5.0 tests
 
986
drop table if exists t1, t2, t3;
 
987
create table t1 (i int);
 
988
create table t3 (j int);
 
989
insert into t1 values ();
 
990
insert into t3 values ();
 
991
lock table t1 write, t3 read;
 
992
alter table t1 modify i int default 1;
 
993
insert into t1 values ();
 
994
select * from t1;
 
995
i
 
996
NULL
 
997
1
 
998
alter table t1 change i c char(10) default "Two";
 
999
insert into t1 values ();
 
1000
select * from t1;
 
1001
c
 
1002
NULL
 
1003
1
 
1004
Two
 
1005
alter table t1 modify c char(10) default "Three", rename to t2;
 
1006
select * from t1;
 
1007
ERROR HY000: Table 't1' was not locked with LOCK TABLES
 
1008
select * from t2;
 
1009
ERROR HY000: Table 't2' was not locked with LOCK TABLES
 
1010
select * from t3;
 
1011
j
 
1012
NULL
 
1013
unlock tables;
 
1014
insert into t2 values ();
 
1015
select * from t2;
 
1016
c
 
1017
NULL
 
1018
1
 
1019
Two
 
1020
Three
 
1021
lock table t2 write, t3 read;
 
1022
alter table t2 change c vc varchar(100) default "Four", rename to t1;
 
1023
select * from t1;
 
1024
ERROR HY000: Table 't1' was not locked with LOCK TABLES
 
1025
select * from t2;
 
1026
ERROR HY000: Table 't2' was not locked with LOCK TABLES
 
1027
select * from t3;
 
1028
j
 
1029
NULL
 
1030
unlock tables;
 
1031
insert into t1 values ();
 
1032
select * from t1;
 
1033
vc
 
1034
NULL
 
1035
1
 
1036
Two
 
1037
Three
 
1038
Four
 
1039
drop tables t1, t3;
798
1040
DROP TABLE IF EXISTS `t+1`, `t+2`;
799
1041
CREATE TABLE `t+1` (c1 INT);
800
1042
ALTER TABLE  `t+1` RENAME `t+2`;
801
1043
CREATE TABLE `t+1` (c1 INT);
802
1044
ALTER TABLE  `t+1` RENAME `t+2`;
803
 
ERROR 42S01: Table 'test.t+2' already exists
 
1045
ERROR 42S01: Table 't+2' already exists
804
1046
DROP TABLE   `t+1`, `t+2`;
805
1047
CREATE TEMPORARY TABLE `tt+1` (c1 INT);
806
1048
ALTER TABLE  `tt+1` RENAME `tt+2`;
807
1049
CREATE TEMPORARY TABLE `tt+1` (c1 INT);
808
1050
ALTER TABLE  `tt+1` RENAME `tt+2`;
809
 
ERROR 42S01: Table 'test.#tt+2' already exists
 
1051
ERROR 42S01: Table 'tt+2' already exists
810
1052
SHOW CREATE TABLE `tt+1`;
811
1053
Table   Create Table
812
1054
tt+1    CREATE TEMPORARY TABLE `tt+1` (
813
 
  `c1` INT DEFAULT NULL
814
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1055
  `c1` int(11) DEFAULT NULL
 
1056
) ENGINE=MyISAM DEFAULT CHARSET=latin1
815
1057
SHOW CREATE TABLE `tt+2`;
816
1058
Table   Create Table
817
1059
tt+2    CREATE TEMPORARY TABLE `tt+2` (
818
 
  `c1` INT DEFAULT NULL
819
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1060
  `c1` int(11) DEFAULT NULL
 
1061
) ENGINE=MyISAM DEFAULT CHARSET=latin1
820
1062
DROP TABLE   `tt+1`, `tt+2`;
 
1063
CREATE TABLE `#sql1` (c1 INT);
 
1064
CREATE TABLE `@0023sql2` (c1 INT);
 
1065
SHOW TABLES;
 
1066
Tables_in_test
 
1067
#sql1
 
1068
@0023sql2
 
1069
RENAME TABLE `#sql1`     TO `@0023sql1`;
 
1070
RENAME TABLE `@0023sql2` TO `#sql2`;
 
1071
SHOW TABLES;
 
1072
Tables_in_test
 
1073
#sql2
 
1074
@0023sql1
 
1075
ALTER TABLE `@0023sql1`  RENAME `#sql-1`;
 
1076
ALTER TABLE `#sql2`      RENAME `@0023sql-2`;
 
1077
SHOW TABLES;
 
1078
Tables_in_test
 
1079
#sql-1
 
1080
@0023sql-2
 
1081
INSERT INTO `#sql-1`     VALUES (1);
 
1082
INSERT INTO `@0023sql-2` VALUES (2);
 
1083
DROP TABLE `#sql-1`, `@0023sql-2`;
821
1084
CREATE TEMPORARY TABLE `#sql1` (c1 INT);
822
1085
CREATE TEMPORARY TABLE `@0023sql2` (c1 INT);
823
1086
SHOW TABLES;
824
1087
Tables_in_test
825
 
#sql1
826
 
@0023sql2
827
1088
ALTER TABLE `#sql1`      RENAME `@0023sql1`;
828
1089
ALTER TABLE `@0023sql2`  RENAME `#sql2`;
829
1090
SHOW TABLES;
830
1091
Tables_in_test
831
 
#sql2
832
 
@0023sql1
833
1092
INSERT INTO `#sql2`      VALUES (1);
834
1093
INSERT INTO `@0023sql1`  VALUES (2);
835
1094
SHOW CREATE TABLE `#sql2`;
836
1095
Table   Create Table
837
1096
#sql2   CREATE TEMPORARY TABLE `#sql2` (
838
 
  `c1` INT DEFAULT NULL
839
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1097
  `c1` int(11) DEFAULT NULL
 
1098
) ENGINE=MyISAM DEFAULT CHARSET=latin1
840
1099
SHOW CREATE TABLE `@0023sql1`;
841
1100
Table   Create Table
842
1101
@0023sql1       CREATE TEMPORARY TABLE `@0023sql1` (
843
 
  `c1` INT DEFAULT NULL
844
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1102
  `c1` int(11) DEFAULT NULL
 
1103
) ENGINE=MyISAM DEFAULT CHARSET=latin1
845
1104
DROP TABLE `#sql2`, `@0023sql1`;
846
1105
DROP TABLE IF EXISTS t1;
847
1106
DROP TABLE IF EXISTS t2;
848
1107
CREATE TABLE t1 (
849
 
int_field INTEGER NOT NULL,
 
1108
int_field INTEGER UNSIGNED NOT NULL,
850
1109
char_field CHAR(10),
851
1110
INDEX(`int_field`)
852
1111
);
853
1112
DESCRIBE t1;
854
 
Field   Type    Null    Default Default_is_NULL On_Update
855
 
int_field       INTEGER NO              NO      
856
 
char_field      VARCHAR YES             YES     
 
1113
Field   Type    Null    Key     Default Extra
 
1114
int_field       int(10) unsigned        NO      MUL     NULL    
 
1115
char_field      char(10)        YES             NULL    
857
1116
SHOW INDEXES FROM t1;
858
 
Table   Unique  Key_name        Seq_in_index    Column_name
859
 
t1      NO      int_field       1       int_field
 
1117
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment Index_Comment
 
1118
t1      1       int_field       1       int_field       A       NULL    NULL    NULL            BTREE           
860
1119
INSERT INTO t1 VALUES (1, "edno"), (1, "edno"), (2, "dve"), (3, "tri"), (5, "pet");
861
1120
"Non-copy data change - new frm, but old data and index files"
862
 
ALTER TABLE t1 CHANGE int_field unsigned_int_field INTEGER NOT NULL, RENAME t2;
 
1121
ALTER TABLE t1
 
1122
CHANGE int_field unsigned_int_field INTEGER UNSIGNED NOT NULL,
 
1123
RENAME t2;
863
1124
SELECT * FROM t1 ORDER BY int_field;
864
1125
ERROR 42S02: Table 'test.t1' doesn't exist
865
1126
SELECT * FROM t2 ORDER BY unsigned_int_field;
870
1131
3       tri
871
1132
5       pet
872
1133
DESCRIBE t2;
873
 
Field   Type    Null    Default Default_is_NULL On_Update
874
 
unsigned_int_field      INTEGER NO              NO      
875
 
char_field      VARCHAR YES             YES     
876
 
DESCRIBE t2;
877
 
Field   Type    Null    Default Default_is_NULL On_Update
878
 
unsigned_int_field      INTEGER NO              NO      
879
 
char_field      VARCHAR YES             YES     
880
 
ALTER TABLE t2 MODIFY unsigned_int_field BIGINT NOT NULL;
881
 
DESCRIBE t2;
882
 
Field   Type    Null    Default Default_is_NULL On_Update
883
 
unsigned_int_field      BIGINT  NO              NO      
884
 
char_field      VARCHAR YES             YES     
 
1134
Field   Type    Null    Key     Default Extra
 
1135
unsigned_int_field      int(10) unsigned        NO      MUL     NULL    
 
1136
char_field      char(10)        YES             NULL    
 
1137
DESCRIBE t2;
 
1138
Field   Type    Null    Key     Default Extra
 
1139
unsigned_int_field      int(10) unsigned        NO      MUL     NULL    
 
1140
char_field      char(10)        YES             NULL    
 
1141
ALTER TABLE t2 MODIFY unsigned_int_field BIGINT UNSIGNED NOT NULL;
 
1142
DESCRIBE t2;
 
1143
Field   Type    Null    Key     Default Extra
 
1144
unsigned_int_field      bigint(20) unsigned     NO      MUL     NULL    
 
1145
char_field      char(10)        YES             NULL    
885
1146
DROP TABLE t2;
886
1147
CREATE TABLE t1 (f1 INT, f2 INT, f3 INT);
887
1148
INSERT INTO t1 VALUES (1, 2, NULL);
897
1158
f1      f2      f3
898
1159
1       2       NULL
899
1160
DROP TABLE t1;
 
1161
create table t1 (c char(10) default "Two");
 
1162
lock table t1 write;
 
1163
insert into t1 values ();
 
1164
alter table t1 modify c char(10) default "Three";
 
1165
unlock tables;
 
1166
select * from t1;
 
1167
c
 
1168
Two
 
1169
check table t1;
 
1170
Table   Op      Msg_type        Msg_text
 
1171
test.t1 check   status  OK
 
1172
drop table t1;