37
38
drop table if exists t1;
40
create table t1 (ordid int(8) not null auto_increment, ord varchar(50) not null, primary key (ord,ordid)) engine=heap;
41
create table t1 (ordid int not null auto_increment, ord varchar(50) not null, primary key (ord,ordid)) engine=heap;
43
44
create table not_existing_database.test (a int);
60
61
create table t1 (a datetime on update now());
62
63
create table t1 (a int default 100 auto_increment);
64
create table t1 (a int default 1000);
64
# TODO: Should this really fail? What's wrong with default 1000 ???
66
#create table t1 (a int default 1000);
66
68
create table t1 (a varchar(5) default 'abcdef');
217
219
create table t1 select 1,2,3;
218
220
create table if not exists t1 select 1,2;
220
221
create table if not exists t1 select 1,2,3,4;
221
222
create table if not exists t1 select 1;
222
223
select * from t1;
230
231
create table t1 (a int not null, b int, primary key (a));
231
232
insert into t1 values (1,1);
232
create table if not exists t1 select 2;
233
# TODO: BUG here, this is filling in right to left for some reason
234
#create table if not exists t1 select 2;
233
235
select * from t1;
234
236
create table if not exists t1 select 3 as 'a',4 as 'b';
235
237
--error ER_DUP_ENTRY
270
272
create table t1 (a int, key(a));
271
273
create table t2 (b int, foreign key(b) references t1(a), key(b));
272
275
drop table if exists t1,t2;
276
drop table if exists t2,t1;
275
279
# Test for CREATE TABLE .. LIKE ..
340
344
values(2,-2,2,'1825-12-14','a','2003-1-1 3:2:1','4:3:2','binary data');
341
345
select * from t1;
343
ifnull(b,cast(-7 as signed)) as b,
344
ifnull(c,cast(7 as)) as c,
345
349
ifnull(d,cast('2000-01-01' as date)) as d,
346
350
ifnull(e,cast('b' as char)) as e,
347
351
ifnull(f,cast('2000-01-01' as datetime)) as f,
356
ifnull(b,cast(-7 as signed)) as b,
357
ifnull(c,cast(7 as)) as c,
358
362
ifnull(d,cast('2000-01-01' as date)) as d,
359
363
ifnull(e,cast('b' as char)) as e,
360
364
ifnull(f,cast('2000-01-01' as datetime)) as f,
366
370
select * from t2;
367
371
drop table t1, t2;
369
create table t1 (a int, b int, c mediumint, d int, e bigint, f float(3,2), g double(4,3), h decimal(5,4), i year, j date, k timestamp, l datetime, m enum('a','b'), n set('a','b'), o char(10));
370
create table t2 select ifnull(a,a), ifnull(b,b), ifnull(c,c), ifnull(d,d), ifnull(e,e), ifnull(f,f), ifnull(g,g), ifnull(h,h), ifnull(i,i), ifnull(j,j), ifnull(k,k), ifnull(l,l), ifnull(m,m), ifnull(n,n), ifnull(o,o) from t1;
373
create table t1 (a int, b int, d int, e bigint, f float(3,2), g double(4,3), h decimal(5,4), j date, k timestamp, l datetime, m enum('a','b'), o char(10));
374
create table t2 select ifnull(a,a), ifnull(b,b), ifnull(d,d), ifnull(e,e), ifnull(f,f), ifnull(g,g), ifnull(h,h), ifnull(j,j), ifnull(k,k), ifnull(l,l), ifnull(m,m), ifnull(o,o) from t1;
371
375
show create table t2;
372
376
drop table t1,t2;
395
399
# test for bug #1427 "enum allows duplicate values in the list"
398
create table t1(cenum enum('a'), cset set('b'));
399
create table t2(cenum enum('a','a'), cset set('b','b'));
400
create table t3(cenum enum('a','A','a','c','c'), cset set('b','B','b','d','d'));
401
drop table t1, t2, t3;
402
create table t1(cenum enum('a'));
404
create table t2(cenum enum('a','a'));
406
create table t3(cenum enum('a','A','a','c','c'));
409
415
select database();
410
416
drop database mysqltest;
411
417
select database();
413
# Connect without a database as user mysqltest_1
414
create user mysqltest_1;
415
connect (user1,localhost,mysqltest_1,,*NO-ONE*);
417
select database(), user();
420
drop user mysqltest_1;
424
421
# Test for Bug 856 'Naming a key "Primary" causes trouble'
428
create table t1 (a int, index `primary` (a));
430
create table t1 (a int, index `PRIMARY` (a));
432
create table t1 (`primary` int, index(`primary`));
433
show create table t1;
434
create table t2 (`PRIMARY` int, index(`PRIMARY`));
435
show create table t2;
437
create table t3 (a int);
439
alter table t3 add index `primary` (a);
441
alter table t3 add index `PRIMARY` (a);
443
create table t4 (`primary` int);
444
alter table t4 add index(`primary`);
445
show create table t4;
446
create table t5 (`PRIMARY` int);
447
alter table t5 add index(`PRIMARY`);
448
show create table t5;
450
drop table t1, t2, t3, t4, t5;
424
## TODO: Is this really a bug? It works in Drizzle. Should it?
426
#create table t1 (a int, index `primary` (a));
428
#create table t1 (a int, index `PRIMARY` (a));
430
#create table t1 (`primary` int, index(`primary`));
431
#show create table t1;
432
#create table t2 (`PRIMARY` int, index(`PRIMARY`));
433
#show create table t2;
435
#create table t3 (a int);
437
#alter table t3 add index `primary` (a);
439
#alter table t3 add index `PRIMARY` (a);
441
#create table t4 (`primary` int);
442
#alter table t4 add index(`primary`);
443
#show create table t4;
444
#create table t5 (`PRIMARY` int);
445
#alter table t5 add index(`PRIMARY`);
446
#show create table t5;
448
#drop table t1, t2, t3, t4, t5;
453
451
# bug #3266 TEXT in CREATE TABLE SELECT
463
461
SELECT * FROM t3;
464
462
drop table t1, t2, t3;
467
# Bug#9666: Can't use 'DEFAULT FALSE' for column of type bool
469
create table t1 (b bool not null default false);
470
create table t2 (b bool not null default true);
471
insert into t1 values ();
472
insert into t2 values ();
478
466
# Bug#10224 - ANALYZE TABLE crashing with simultaneous
481
469
# an improper fix is present.
483
471
create table t1 (a int);
472
## TODO: Should this statement fail?
485
474
create table t1 select * from t1;
486
--error ER_WRONG_OBJECT
487
create table t2 union = (t1) select * from t1;
475
## TODO: Huh? --error ER_WRONG_OBJECT
476
#create table t2 union = (t1) select * from t1;
488
477
flush tables with read lock;
506
495
# Bug #12537: UNION produces longtext instead of varchar
508
CREATE TABLE t1 (f1 VARCHAR(255) CHARACTER SET utf8);
497
CREATE TABLE t1 (f1 VARCHAR(255));
509
498
CREATE TABLE t2 AS SELECT LEFT(f1,171) AS f2 FROM t1 UNION SELECT LEFT(f1,171) AS f2 FROM t1;
511
500
DROP TABLE t1,t2;
529
518
drop table if exists test.t1;
530
519
--enable_warnings
533
# Bug #6859: Bogus error message on attempt to CREATE TABLE t LIKE view
535
create database mysqltest;
537
create view v1 as select 'foo' from dual;
539
create table t1 like v1;
541
drop database mysqltest;
542
521
# Bug #6008 MySQL does not create warnings when
543
522
# creating database and using IF NOT EXISTS
545
524
create database mysqltest;
546
create database if not exists mysqltest character set latin2;
525
create database if not exists mysqltest;
547
526
show create database mysqltest;
548
527
drop database mysqltest;
565
544
# calculation of number of NULLs.
567
546
CREATE TABLE t2 (
568
a int(11) default NULL
570
549
insert into t2 values(111);
573
552
create table t1 (
574
a varchar(12) charset utf8 collate utf8_bin not null,
553
a varchar(12) collate utf8_bin not null,
575
554
b int not null, primary key (a)
576
555
) select a, 1 as b from t2 ;
577
556
show create table t1;
581
560
create table t1 (
582
a varchar(12) charset utf8 collate utf8_bin not null,
561
a varchar(12) collate utf8_bin not null,
583
562
b int not null, primary key (a)
584
563
) select a, 1 as c from t2 ;
585
show create table t1;
589
565
create table t1 (
590
a varchar(12) charset utf8 collate utf8_bin not null,
566
a varchar(12) collate utf8_bin not null,
591
567
b int null, primary key (a)
592
568
) select a, 1 as c from t2 ;
593
569
show create table t1;
597
572
create table t1 (
598
a varchar(12) charset utf8 collate utf8_bin not null,
573
a varchar(12) collate utf8_bin not null,
599
574
b int not null, primary key (a)
600
575
) select 'a' as a , 1 as b from t2 ;
601
576
show create table t1;
605
579
create table t1 (
606
a varchar(12) charset utf8 collate utf8_bin,
580
a varchar(12) collate utf8_bin,
607
581
b int not null, primary key (a)
608
582
) select 'a' as a , 1 as b from t2 ;
609
583
show create table t1;
619
593
create table t2 (
620
a1 varchar(12) charset utf8 collate utf8_bin not null,
594
a1 varchar(12) collate utf8_bin not null,
621
595
a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int,
623
597
) select a1,a2,a3,a4,a5,a6,a7,a8,a9 from t1 ;
627
601
create table t2 (
628
a1 varchar(12) charset utf8 collate utf8_bin,
602
a1 varchar(12) collate utf8_bin,
629
603
a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int
630
604
) select a1,a2,a3,a4,a5,a6,a7,a8,a9 from t1;
640
614
create table t2 (
641
a1 varchar(12) charset utf8 collate utf8_bin not null,
615
a1 varchar(12) collate utf8_bin not null,
642
616
a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int,
644
618
) select a1,a2,a3,a4,a5,a6,a7,a8,a9 from t1 ;
688
654
create table t1 select * from t1;
689
655
# Error which happens before select_create::prepare()
690
656
--error ER_CANT_AGGREGATE_2COLLATIONS
691
create table t1 select coalesce('a' collate latin1_swedish_ci,'b' collate latin1_bin);
657
create table t1 select coalesce('a' collate utf8_swedish_ci,'b' collate utf8_bin);
692
658
# Error during table creation
693
659
--error ER_KEY_COLUMN_DOES_NOT_EXITS
694
660
create table t1 (primary key(a)) select "b" as b;
695
661
# Error in select_create::prepare() which is not related to table creation
696
create table t1 (a int);
697
--error ER_WRONG_VALUE_COUNT_ON_ROW
698
create table if not exists t1 select 1 as a, 2 as b;
662
# TODO: This really should be failing...
663
# create table t1 (a int);
664
# --error ER_WRONG_VALUE_COUNT_ON_ROW
665
# create table if not exists t1 select 1 as a, 2 as b;
700
667
# Finally error which happens during insert
701
668
--error ER_DUP_ENTRY
702
669
create table t1 (primary key (a)) (select 1 as a) union all (select 1 as a);
703
670
# What happens if table already exists ?
704
671
create table t1 (i int);
705
--error ER_TABLE_EXISTS_ERROR
706
create table t1 select 1 as i;
672
# TODO: BUG lp:311045
673
#--error ER_TABLE_EXISTS_ERROR
674
#create table t1 select 1 as i;
707
675
create table if not exists t1 select 1 as i;
708
676
select * from t1;
709
678
# Error before select_create::prepare()
710
679
--error ER_CANT_AGGREGATE_2COLLATIONS
711
create table t1 select coalesce('a' collate latin1_swedish_ci,'b' collate latin1_bin);
680
create table t1 select coalesce('a' collate utf8_swedish_ci,'b' collate utf8_bin);
713
681
# Error which happens during insertion of rows
714
alter table t1 add primary key (i);
716
create table if not exists t1 (select 2 as i) union all (select 2 as i);
682
# TODO: Bug lp:311072
683
# create table t1 (i int);
684
# alter table t1 add primary key (i);
685
# --error ER_DUP_ENTRY
686
# create table if not exists t1 (select 2 as i) union all (select 2 as i);
721
691
# Base vs temporary tables dillema (a.k.a. bug#24508 "Inconsistent
1192
1162
CREATE TEMPORARY TABLE t2 (primary key (a)) select * from t1;
1193
1163
# This should give warning
1194
1164
drop table if exists t2;
1195
CREATE TABLE t2 (a int, b int, primary key (a));
1196
--error ER_DUP_ENTRY
1197
CREATE TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
1200
--error ER_DUP_ENTRY
1201
INSERT INTO t2 select * from t1;
1165
# TODO: Bug lp:311072
1166
#CREATE TABLE t2 (a int, b int, primary key (a));
1167
#--error ER_DUP_ENTRY
1168
#CREATE TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
1171
#--error ER_DUP_ENTRY
1172
#INSERT INTO t2 select * from t1;
1205
1176
CREATE TEMPORARY TABLE t2 (a int, b int, primary key (a));
1206
1177
--error ER_DUP_ENTRY
1257
1227
index имя_индекса_в_кодировке_утф8_длиной_больше_чем_48 (имя_поля_в_кодировке_утф8_длиной_больше_чем_45)
1260
create view имя_вью_кодировке_утф8_длиной_больше_чем_42 as
1261
select имя_поля_в_кодировке_утф8_длиной_больше_чем_45
1262
from имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48;
1264
# database, table, field, key, view
1231
# database, table, field, key
1265
1232
select * from имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48;
1267
1234
select TABLE_NAME from information_schema.tables where
1273
1240
select INDEX_NAME from information_schema.statistics where
1274
1241
table_schema='test';
1276
select TABLE_NAME from information_schema.views where
1277
table_schema='test';
1279
1243
show create table имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48;
1280
show create view имя_вью_кодировке_утф8_длиной_больше_чем_42;
1282
# procedure, function, trigger
1284
create trigger имя_триггера_в_кодировке_утф8_длиной_больше_чем_49
1285
before insert on имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48 for each row set @a:=1;
1286
select TRIGGER_NAME from information_schema.triggers where
1287
trigger_schema='test';
1288
drop trigger имя_триггера_в_кодировке_утф8_длиной_больше_чем_49;
1291
очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_66
1292
before insert on имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48 for each row set @a:=1;
1294
drop trigger очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_66;
1296
create procedure имя_процедуры_в_кодировке_утф8_длиной_больше_чем_50()
1299
select ROUTINE_NAME from information_schema.routines where
1300
routine_schema='test';
1301
drop procedure имя_процедуры_в_кодировке_утф8_длиной_больше_чем_50;
1303
create procedure очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_66()
1307
create function имя_функции_в_кодировке_утф8_длиной_больше_чем_49()
1310
select ROUTINE_NAME from information_schema.routines where
1311
routine_schema='test';
1312
drop function имя_функции_в_кодировке_утф8_длиной_больше_чем_49;
1314
create function очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_66()
1318
drop view имя_вью_кодировке_утф8_длиной_больше_чем_42;
1319
1245
drop table имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48;
1323
# Bug#21136 CREATE TABLE SELECT within CREATE TABLE SELECT causes server crash
1327
drop table if exists t1,t2,t3;
1328
drop function if exists f1;
1332
create function f1() returns int
1335
create temporary table t3 select 1 i;
1336
set res:= (select count(*) from t1);
1337
drop temporary table t3;
1341
create table t1 as select 1;
1342
create table t2 as select f1() from t1;
1347
1249
# Bug#25629 CREATE TABLE LIKE does not work with INFORMATION_SCHEMA
1377
1276
c1 INT DEFAULT 12 COMMENT 'column1',
1378
1277
c2 INT NULL COMMENT 'column2',
1379
1278
c3 INT NOT NULL COMMENT 'column3',
1380
c4 VARCHAR(255) CHARACTER SET utf8 NOT NULL DEFAULT 'a',
1279
c4 VARCHAR(255) NOT NULL DEFAULT 'a',
1381
1280
c5 VARCHAR(255) COLLATE utf8_unicode_ci NULL DEFAULT 'b',
1382
1281
c6 VARCHAR(255))
1424
SET sql_mode = NO_ZERO_DATE;
1427
--error ER_INVALID_DEFAULT
1428
1324
CREATE TABLE t2(c1 TIMESTAMP, c2 TIMESTAMP DEFAULT 0);
1431
--error ER_INVALID_DEFAULT
1432
1328
CREATE TABLE t2(c1 TIMESTAMP, c2 TIMESTAMP);
1435
1332
--echo # -- Check that NULL column still can be created.
1439
1336
--echo # -- Check ALTER TABLE.
1440
--error ER_INVALID_DEFAULT
1441
1337
ALTER TABLE t1 ADD INDEX(c1);
1444
1340
--echo # -- Check DATETIME.
1449
1343
CREATE TABLE t3(c1 DATETIME NOT NULL);
1450
1344
INSERT INTO t3 VALUES (0);
1453
SET sql_mode = TRADITIONAL;
1456
--error ER_TRUNCATED_WRONG_VALUE
1457
1347
ALTER TABLE t3 ADD INDEX(c1);
1460
1350
--echo # -- Cleanup.
1468
1357
--echo # -- End of Bug#18834.
1470
###########################################################################
1474
--echo # -- Bug#34274: Invalid handling of 'DEFAULT 0' for YEAR data type.
1479
DROP TABLE IF EXISTS t1;
1483
CREATE TABLE t1(c1 YEAR DEFAULT 2008, c2 YEAR DEFAULT 0);
1486
SHOW CREATE TABLE t1;
1489
INSERT INTO t1 VALUES();
1495
ALTER TABLE t1 MODIFY c1 YEAR DEFAULT 0;
1498
SHOW CREATE TABLE t1;
1501
INSERT INTO t1 VALUES();
1510
--echo # -- End of Bug#34274
1512
###########################################################################
1515
--echo End of 5.1 tests