~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/alter_table.test

Merge/fix in FAQ.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
select * from t1;
24
24
drop table t1;
25
25
 
26
 
create table t1 (bandID INT NOT NULL PRIMARY KEY, payoutID int NOT NULL);
 
26
create table t1 (bandID INT UNSIGNED NOT NULL PRIMARY KEY, payoutID SMALLINT UNSIGNED NOT NULL);
27
27
insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12);
28
28
alter table t1 add column new_col int;
29
29
select * from t1;
34
34
# Check that pack_keys and dynamic length rows are not forced. 
35
35
 
36
36
CREATE TABLE t1 (
37
 
GROUP_ID int DEFAULT '0' NOT NULL,
38
 
LANG_ID int DEFAULT '0' NOT NULL,
 
37
GROUP_ID int(10) unsigned DEFAULT '0' NOT NULL,
 
38
LANG_ID smallint(5) unsigned DEFAULT '0' NOT NULL,
39
39
NAME varchar(80) DEFAULT '' NOT NULL,
40
40
PRIMARY KEY (GROUP_ID,LANG_ID),
41
41
KEY NAME (NAME));
56
56
drop table t1;
57
57
 
58
58
CREATE TABLE t1 (
59
 
  id int NOT NULL default '0',
60
 
  category_id int NOT NULL default '0',
61
 
  type_id int NOT NULL default '0',
 
59
  id int(11) unsigned NOT NULL default '0',
 
60
  category_id tinyint(4) unsigned NOT NULL default '0',
 
61
  type_id tinyint(4) unsigned NOT NULL default '0',
62
62
  body text NOT NULL,
63
 
  user_id int NOT NULL default '0',
 
63
  user_id int(11) unsigned NOT NULL default '0',
64
64
  status enum('new','old') NOT NULL default 'new',
65
65
  PRIMARY KEY (id)
66
66
) ENGINE=MyISAM;
72
72
# The following combination found a hang-bug in MyISAM
73
73
#
74
74
 
75
 
CREATE TABLE t1 (AnamneseId int NOT NULL auto_increment,B BLOB,PRIMARY KEY (AnamneseId)) engine=myisam;
 
75
CREATE TABLE t1 (AnamneseId int(10) unsigned NOT NULL auto_increment,B BLOB,PRIMARY KEY (AnamneseId)) engine=myisam;
76
76
insert into t1 values (null,"hello");
77
77
LOCK TABLES t1 WRITE;
78
78
ALTER TABLE t1 ADD Column new_col int not null;
84
84
# Drop and add an auto_increment column
85
85
#
86
86
 
87
 
create table t1 (i int not null auto_increment primary key);
 
87
create table t1 (i int unsigned not null auto_increment primary key);
88
88
insert into t1 values (null),(null),(null),(null);
89
 
alter table t1 drop i,add i int not null auto_increment, drop primary key, add primary key (i);
 
89
alter table t1 drop i,add i int unsigned not null auto_increment, drop primary key, add primary key (i);
90
90
select * from t1;
91
91
drop table t1;
92
92
 
120
120
alter table t1;
121
121
show keys from t1;
122
122
#let $1=10000;
123
 
set autocommit=0;
124
 
begin;
125
123
let $1=10;
126
124
while ($1)
127
125
{
128
126
 eval insert into t1 values($1,RAND()*1000,RAND()*1000,RAND());
129
127
 dec $1;
130
128
}
131
 
commit;
132
 
set autocommit=1;
133
129
alter table t1 enable keys;
134
130
show keys from t1;
135
131
drop table t1;
138
134
# Alter table and rename
139
135
#
140
136
 
141
 
create table t1 (i int not null auto_increment primary key);
 
137
create table t1 (i int unsigned not null auto_increment primary key);
142
138
alter table t1 rename t2;
143
139
alter table t2 rename t1, add c char(10) comment "no comment";
144
140
show columns from t1;
148
144
 
149
145
create table t1 (a int, b int);
150
146
let $1=100;
151
 
set autocommit=0;
152
 
begin;
153
147
while ($1)
154
148
{
155
149
 eval insert into t1 values(1,$1), (2,$1), (3, $1);
156
150
 dec $1;
157
151
}
158
 
commit;
159
 
set autocommit=1;
160
152
alter table t1 add unique (a,b), add key (b);
161
153
show keys from t1;
162
154
analyze table t1;
264
256
drop table t1;
265
257
 
266
258
#
 
259
# Test that data get converted when character set is changed
 
260
# Test that data doesn't get converted when src or dst is BINARY/BLOB
 
261
#
 
262
set names koi8r;
 
263
create table t1 (a char(10) character set koi8r);
 
264
insert into t1 values ('����');
 
265
select a,hex(a) from t1;
 
266
alter table t1 change a a char(10) character set cp1251;
 
267
select a,hex(a) from t1;
 
268
alter table t1 change a a binary(4);
 
269
select a,hex(a) from t1;
 
270
alter table t1 change a a char(10) character set cp1251;
 
271
select a,hex(a) from t1;
 
272
alter table t1 change a a char(10) character set koi8r;
 
273
select a,hex(a) from t1;
 
274
alter table t1 change a a varchar(10) character set cp1251;
 
275
select a,hex(a) from t1;
 
276
alter table t1 change a a char(10) character set koi8r;
 
277
select a,hex(a) from t1;
 
278
alter table t1 change a a text character set cp1251;
 
279
select a,hex(a) from t1;
 
280
alter table t1 change a a char(10) character set koi8r;
 
281
select a,hex(a) from t1;
 
282
delete from t1;
 
283
 
 
284
#
 
285
# Test ALTER TABLE .. CHARACTER SET ..
 
286
#
 
287
show create table t1;
 
288
alter table t1 DEFAULT CHARACTER SET latin1;
 
289
show create table t1;
 
290
alter table t1 CONVERT TO CHARACTER SET latin1;
 
291
show create table t1;
 
292
alter table t1 DEFAULT CHARACTER SET cp1251;
 
293
show create table t1;
 
294
 
 
295
drop table t1;
 
296
 
 
297
#
 
298
# Bug#2821
 
299
# Test that table CHARACTER SET does not affect blobs
 
300
#
 
301
create table t1 (myblob longblob,mytext longtext) 
 
302
default charset latin1 collate latin1_general_cs;
 
303
show create table t1;
 
304
alter table t1 character set latin2;
 
305
show create table t1;
 
306
drop table t1;
 
307
 
 
308
#
267
309
# Bug 2361 (Don't drop UNIQUE with DROP PRIMARY KEY)
268
310
#
269
311
 
293
335
DROP TABLE T12207;
294
336
 
295
337
#
 
338
# Bug #6479  ALTER TABLE ... changing charset fails for TEXT columns
 
339
#
 
340
# The column's character set was changed but the actual data was not
 
341
# modified. In other words, the values were reinterpreted
 
342
# as UTF8 instead of being converted.
 
343
create table t1 (a text) character set koi8r;
 
344
insert into t1 values (_koi8r'����');
 
345
select hex(a) from t1;
 
346
alter table t1 convert to character set cp1251;
 
347
select hex(a) from t1;
 
348
drop table t1;
 
349
 
 
350
#
296
351
# Test for bug #7884 "Able to add invalid unique index on TIMESTAMP prefix"
297
352
# MySQL should not think that packed field with non-zero decimals is
298
353
# geometry field and allow to create prefix index which is
529
584
# Bug #14693 (ALTER SET DEFAULT doesn't work)
530
585
#
531
586
 
532
 
create table t1 (mycol int not null);
 
587
create table t1 (mycol int(10) not null);
533
588
alter table t1 alter column mycol set default 0;
534
589
desc t1;
535
590
drop table t1;
538
593
# Bug#25262 Auto Increment lost when changing Engine type
539
594
#
540
595
 
541
 
create table t1(id int primary key auto_increment) engine=heap;
 
596
create table t1(id int(8) primary key auto_increment) engine=heap;
542
597
 
543
598
insert into t1 values (null);
544
599
insert into t1 values (null);
613
668
# without # prefix is not allowed for TEXT columns, while index
614
669
# is defined with prefix.
615
670
616
 
create table t1 (t varchar(255) default null, key t (t(80))) engine=myisam;
 
671
create table t1 (t varchar(255) default null, key t (t(80)))
 
672
engine=myisam default charset=latin1;
617
673
alter table t1 change t t text;
618
674
drop table t1;
619
675
 
628
684
SELECT LENGTH(s) FROM t1;
629
685
DROP TABLE t1;
630
686
 
631
 
CREATE TABLE t1 (s varbinary(8));
 
687
CREATE TABLE t1 (s BINARY(8));
632
688
INSERT INTO t1 VALUES ('test');
633
689
SELECT LENGTH(s) FROM t1;
634
690
SELECT HEX(s) FROM t1;
635
 
ALTER TABLE t1 MODIFY s varbinary(10);
 
691
ALTER TABLE t1 MODIFY s BINARY(10);
636
692
SELECT HEX(s) FROM t1;
637
693
SELECT LENGTH(s) FROM t1;
638
694
DROP TABLE t1;
765
821
DROP TABLE IF EXISTS t2;
766
822
--enable_warnings
767
823
CREATE TABLE t1 (
768
 
  int_field INTEGER NOT NULL,
 
824
  int_field INTEGER UNSIGNED NOT NULL,
769
825
  char_field CHAR(10),
770
826
  INDEX(`int_field`)
771
827
);
776
832
 
777
833
INSERT INTO t1 VALUES (1, "edno"), (1, "edno"), (2, "dve"), (3, "tri"), (5, "pet"); 
778
834
--echo "Non-copy data change - new frm, but old data and index files"
779
 
ALTER TABLE t1 CHANGE int_field unsigned_int_field INTEGER NOT NULL, RENAME t2;
 
835
ALTER TABLE t1
 
836
  CHANGE int_field unsigned_int_field INTEGER UNSIGNED NOT NULL,
 
837
  RENAME t2;
780
838
 
781
839
--error ER_NO_SUCH_TABLE
782
840
SELECT * FROM t1 ORDER BY int_field;
783
841
SELECT * FROM t2 ORDER BY unsigned_int_field;
784
842
DESCRIBE t2;
785
843
DESCRIBE t2;
786
 
ALTER TABLE t2 MODIFY unsigned_int_field BIGINT NOT NULL;
 
844
ALTER TABLE t2 MODIFY unsigned_int_field BIGINT UNSIGNED NOT NULL;
787
845
DESCRIBE t2;
788
846
 
789
847
DROP TABLE t2;