14
14
col5 enum('PENDING', 'ACTIVE', 'DISABLED') not null,
15
15
col6 int not null, to_be_deleted int);
16
16
insert into t1 values (2,4,3,5,"PENDING",1,7);
19
--error ER_INVALID_ALTER_TABLE_FOR_NOT_NULL
21
18
add column col4_5 varchar(20) not null after col4,
22
19
add column col7 varchar(30) not null after col5,
23
add column col8 datetime not null default '1000-01-01 00:00:00', drop column to_be_deleted,
24
change column col2 fourth varchar(30) not null after col3,
25
modify column col6 int not null first;
28
add column col4_5 varchar(20) DEFAULT "added" not null after col4,
29
add column col7 varchar(30) DEFAULT "added" not null after col5,
30
add column col8 datetime not null default '1000-01-01 00:00:00',
31
drop column to_be_deleted,
32
change column col2 fourth varchar(30) not null after col3,
33
modify column col6 int not null first;
20
add column col8 datetime not null, drop column to_be_deleted,
21
change column col2 fourth varchar(30) not null after col3,
22
modify column col6 int not null first;
38
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);
39
27
insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12);
40
28
alter table t1 add column new_col int;
46
34
# Check that pack_keys and dynamic length rows are not forced.
49
GROUP_ID int DEFAULT '0' NOT NULL,
50
LANG_ID int DEFAULT '0' NOT NULL,
37
GROUP_ID int unsigned DEFAULT '0' NOT NULL,
38
LANG_ID smallint unsigned DEFAULT '0' NOT NULL,
51
39
NAME varchar(80) DEFAULT '' NOT NULL,
52
40
PRIMARY KEY (GROUP_ID,LANG_ID),
54
--replace_column 1 # 6 # 7 # 8 # 9 # 10 #
42
#show table status like "t1";
55
43
ALTER TABLE t1 CHANGE NAME NAME CHAR(80) not null;
56
44
--replace_column 8 #
45
SHOW FULL COLUMNS FROM t1;
70
CREATE TEMPORARY TABLE t1 (
71
id int NOT NULL default '0',
72
category_id int NOT NULL default '0',
73
type_id int NOT NULL default '0',
59
id int unsigned NOT NULL default '0',
60
category_id tinyint unsigned NOT NULL default '0',
61
type_id tinyint unsigned NOT NULL default '0',
74
62
body text NOT NULL,
75
user_id int NOT NULL default '0',
63
user_id int unsigned NOT NULL default '0',
76
64
status enum('new','old') NOT NULL default 'new',
72
# The following combination found a hang-bug in MyISAM
75
CREATE TABLE t1 (AnamneseId int unsigned NOT NULL auto_increment,B BLOB,PRIMARY KEY (AnamneseId)) engine=myisam;
76
insert into t1 values (null,"hello");
78
ALTER TABLE t1 ADD Column new_col int not null;
84
84
# Drop and add an auto_increment column
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);
167
# Test ALTER TABLE ENABLE/DISABLE keys when things are locked
171
Host varchar(16) binary NOT NULL default '',
172
User varchar(16) binary NOT NULL default '',
173
PRIMARY KEY (Host,User)
176
ALTER TABLE t1 DISABLE KEYS;
177
LOCK TABLES t1 WRITE;
178
INSERT INTO t1 VALUES ('localhost','root'),('localhost',''),('games','monty');
180
ALTER TABLE t1 ENABLE KEYS;
167
186
# Test with two keys
170
CREATE TEMPORARY TABLE t1 (
171
Host varchar(16) NOT NULL default '',
172
User varchar(16) NOT NULL default '',
190
Host varchar(16) binary NOT NULL default '',
191
User varchar(16) binary NOT NULL default '',
173
192
PRIMARY KEY (Host,User),
177
196
ALTER TABLE t1 DISABLE KEYS;
198
LOCK TABLES t1 WRITE;
179
199
INSERT INTO t1 VALUES ('localhost','root'),('localhost','');
181
201
ALTER TABLE t1 ENABLE KEYS;
206
# Test RENAME with LOCK TABLES
207
LOCK TABLES t1 WRITE;
186
208
ALTER TABLE t1 RENAME t2;
187
210
select * from t2;
217
Host varchar(16) binary NOT NULL default '',
218
User varchar(16) binary NOT NULL default '',
219
PRIMARY KEY (Host,User),
223
LOCK TABLES t1 WRITE;
224
ALTER TABLE t1 DISABLE KEYS;
191
229
# BUG#4717 - check for valid table names
193
231
create table t1 (a int);
211
249
# The following is also part of bug #6236 (CREATE TABLE didn't properly count
212
250
# not null columns for primary keys)
214
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;
215
insert into t1 (a,b,c,d,e,f,g,h,i) values(1,1,1,1,1,1,1,1,1);
216
--replace_column 1 # 6 # 7 # 8 # 9 # 10 #
252
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;
253
insert into t1 (a) values(1);
254
--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
217
255
show table status like 't1';
218
256
alter table t1 modify a int;
219
--replace_column 1 # 6 # 7 # 8 # 9 # 10 #
257
--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
220
258
show table status like 't1';
222
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;
260
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;
223
261
insert into t1 (a) values(1);
224
--replace_column 1 # 6 # 7 # 8 # 9 # 10 #
262
--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
225
263
show table status like 't1';
534
569
#create table t1(f1 int);
535
570
#alter table t1 add column f2 datetime not null, add column f21 date not null;
536
571
#insert into t1 values(1,'2000-01-01','2000-01-01');
537
#--error ER_TRUNCATED_WRONG_VALUE
538
573
#alter table t1 add column f3 datetime not null;
539
#--error ER_TRUNCATED_WRONG_VALUE
540
575
#alter table t1 add column f3 date not null;
541
#--error ER_TRUNCATED_WRONG_VALUE
542
577
#alter table t1 add column f4 datetime not null default '2002-02-02',
543
578
# add column f41 date not null;
544
579
#alter table t1 add column f4 datetime not null default '2002-02-02',
618
653
--echo End of 5.0 tests
656
# Extended test coverage for ALTER TABLE behaviour under LOCK TABLES
657
# It should be consistent across all platforms and for all engines
658
# (Before 5.1 this was not true as behavior was different between
659
# Unix/Windows and transactional/non-transactional tables).
660
# See also innodb_mysql.test
663
drop table if exists t1, t2, t3;
665
create table t1 (i int);
666
create table t3 (j int);
667
insert into t1 values ();
668
insert into t3 values ();
669
# Table which is altered under LOCK TABLES it should stay in list of locked
670
# tables and be available after alter takes place unless ALTER contains RENAME
671
# clause. We should see the new definition of table, of course.
672
lock table t1 write, t3 read;
673
# Example of so-called 'fast' ALTER TABLE
674
alter table t1 modify i int default 1;
675
insert into t1 values ();
677
# And now full-blown ALTER TABLE
678
alter table t1 change i c char(10) default "Two";
679
insert into t1 values ();
681
# If table is renamed then it should be removed from the list
682
# of locked tables. 'Fast' ALTER TABLE with RENAME clause:
683
alter table t1 modify c char(10) default "Three", rename to t2;
684
--error ER_TABLE_NOT_LOCKED
686
--error ER_TABLE_NOT_LOCKED
690
insert into t2 values ();
692
lock table t2 write, t3 read;
693
# Full ALTER TABLE with RENAME
694
alter table t2 change c vc varchar(100) default "Four", rename to t1;
695
--error ER_TABLE_NOT_LOCKED
697
--error ER_TABLE_NOT_LOCKED
701
insert into t1 values ();
621
707
# Bug#18775 - Temporary table from alter table visible to other threads
623
709
# Check if special characters work and duplicates are detected.
637
723
CREATE TEMPORARY TABLE `tt+1` (c1 INT);
638
724
--error ER_TABLE_EXISTS_ERROR
639
725
ALTER TABLE `tt+1` RENAME `tt+2`;
640
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
641
726
SHOW CREATE TABLE `tt+1`;
642
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
643
727
SHOW CREATE TABLE `tt+2`;
644
728
DROP TABLE `tt+1`, `tt+2`;
667
751
INSERT INTO `#sql2` VALUES (1);
668
752
INSERT INTO `@0023sql1` VALUES (2);
669
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
670
753
SHOW CREATE TABLE `#sql2`;
671
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
672
754
SHOW CREATE TABLE `@0023sql1`;
673
755
DROP TABLE `#sql2`, `@0023sql1`;
677
758
# Bug #22369: Alter table rename combined with other alterations causes lost tables
679
760
# This problem happens if the data change is compatible.
696
777
INSERT INTO t1 VALUES (1, "edno"), (1, "edno"), (2, "dve"), (3, "tri"), (5, "pet");
697
778
--echo "Non-copy data change - new frm, but old data and index files"
698
ALTER TABLE t1 CHANGE int_field unsigned_int_field INTEGER NOT NULL, RENAME t2;
780
CHANGE int_field unsigned_int_field INTEGER UNSIGNED NOT NULL,
700
--error ER_TABLE_UNKNOWN
783
--error ER_NO_SUCH_TABLE
701
784
SELECT * FROM t1 ORDER BY int_field;
702
785
SELECT * FROM t2 ORDER BY unsigned_int_field;
705
ALTER TABLE t2 MODIFY unsigned_int_field BIGINT NOT NULL;
788
ALTER TABLE t2 MODIFY unsigned_int_field BIGINT UNSIGNED NOT NULL;