create.test 4.94 KB
Newer Older
1 2 3 4
#
# Check some special create statements.
#

5
drop table if exists t1,t2;
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
create table t1 (b char(0));
insert into t1 values (""),(null);
select * from t1;
drop table if exists t1;

create table t1 (b char(0) not null);
create table if not exists t1 (b char(0) not null);
insert into t1 values (""),(null);
select * from t1;
drop table if exists t1;

#
# Test of some CREATE TABLE'S that should fail
#

21 22 23 24
--error 1146
create table t2 type=heap select * from t1;
--error 1146
create table t2 select auto+1 from t1;
25
drop table if exists t1,t2;
26 27 28 29 30 31
--error 1167
create table t1 (b char(0) not null, index(b));
--error 1164
create table t1 (a int not null auto_increment,primary key (a)) type=heap;
--error 1163
create table t1 (a int not null,b text) type=heap;
32 33
drop table if exists t1;

34 35
--error 1164
create table t1 (ordid int(8) not null auto_increment, ord  varchar(50) not null, primary key (ord,ordid)) type=heap;
36

37 38
-- error 1044,1
create table not_existing_database.test (a int);
39 40 41 42 43 44
--error 1103
create table `a/a` (a int);
--error 1103
create table `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa int);
--error 1059
create table a (`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` int);
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

#
# test of dummy table names
#

create table 1ea10 (1a20 int,1e int);
insert into 1ea10 values(1,1);
select 1ea10.1a20,1e+ 1e+10 from 1ea10;
drop table 1ea10;
create table t1 (t1.index int);
drop table t1;
drop database if exists test_$1;
create database test_$1;
create table test_$1.$test1 (a$1 int, $b int, c$ int);
insert into test_$1.$test1 values (1,2,3);
select a$1, $b, c$ from test_$1.$test1;
create table test_$1.test2$ (a int);
drop table test_$1.test2$;
drop database test_$1;
64

65 66 67 68 69 70 71 72
--error 1103
create table `` (a int);
--error 1103
drop table if exists ``;
--error 1166
create table t1 (`` int);
drop table if exists t1;

73 74 75 76 77 78 79 80 81 82
#
# Test of CREATE ... SELECT with indexes
#

create table t1 (a int auto_increment not null primary key, B CHAR(20));
insert into t1 (b) values ("hello"),("my"),("world");
create table t2 (key (b)) select * from t1;
explain select * from t2 where b="world";
select * from t2 where b="world";
drop table t1,t2;
83 84 85 86 87 88 89 90 91

#
# Test types after CREATE ... SELECT
#

create table t1(x varchar(50) );
create table t2 select x from t1 where 1=2;
describe t1;
describe t2;
92 93 94
drop table t2;
create table t2 select now() as a , curtime() as b, curdate() as c , 1+1 as d , 1.0 + 1 as e , 33333333333333333 + 3 as f;
describe t2;
95
drop table t2;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
96
create table t2 select CAST("2001-12-29" AS DATE) as d, CAST("20:45:11" AS TIME) as t, CAST("2001-12-29  20:45:11" AS DATETIME) as dt;
97
describe t2;
98
drop table t1,t2;
monty@hundin.mysql.fi's avatar
merge  
monty@hundin.mysql.fi committed
99

100 101 102 103 104 105 106
#
# Test of primary key with 32 index
#

create table t1 (a int not null, b int, primary key(a), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b));
show create table t1;
drop table t1;
107 108
create table t1 select if(1,'1','0'), month("2002-08-02");
drop table t1;
109 110 111
create table t1 select if('2002'='2002','Y','N');
select * from t1;
drop table if exists t1;
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128

#
# Test default table type
#
SET SESSION table_type="heap";
SELECT @@table_type;
CREATE TABLE t1 (a int not null);
show create table t1;
drop table t1;
# Test what happens when using a non existing table type
SET SESSION table_type="gemini";
SELECT @@table_type;
CREATE TABLE t1 (a int not null);
show create table t1;
SET SESSION table_type=default;
drop table t1;

129 130 131 132 133 134

#
# ISO requires that primary keys are implicitly NOT NULL
#
create table t1 ( k1 varchar(2), k2 int, primary key(k1,k2));
insert into t1 values ("a", 1), ("b", 2);
135 136 137 138 139 140
--error 1048
insert into t1 values ("c", NULL);
--error 1048
insert into t1 values (NULL, 3);
--error 1048
insert into t1 values (NULL, NULL);
141
drop table t1;
142 143

#
144
# Bug #801
145 146 147 148
#

create table t1 select x'4132';
drop table t1;
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168

#
# bug #1434
#

create table t1 select 1,2,3;
create table if not exists t1 select 1,2;
--error 1136
create table if not exists t1 select 1,2,3,4;
create table if not exists t1 select 1;
select * from t1;
drop table t1;
create table t1 select 1,2,3;
create table if not exists t1 select 1,2;
--error 1136
create table if not exists t1 select 1,2,3,4;
create table if not exists t1 select 1;
select * from t1;
drop table t1;

169 170 171 172 173 174 175 176 177 178 179 180 181
#
# Test create table if not exists with duplicate key error
#

create table t1 (a int not null, b int, primary key (a));
insert into t1 values (1,1);
create table if not exists t1 select 2;
select * from t1;
create table if not exists t1 select 3 as 'a',4 as 'b';
--error 1062
create table if not exists t1 select 3 as 'a',3 as 'b';
select * from t1;
drop table t1;
vva@eagle.mysql.r18.ru's avatar
vva@eagle.mysql.r18.ru committed
182 183 184 185 186 187 188 189 190 191 192 193

#
# Test for Bug #2985 
#   "Table truncated when creating another table name with Spaces"
#

--error 1103
create table `t1 `(a int);
--error 1102
create database `db1 `;
--error 1166;
create table t1(`a ` int);