📄 create.result
字号:
drop table if exists t1,t2,t3,t4,t5;drop database if exists mysqltest;create table t1 (b char(0));insert into t1 values (""),(null);select * from t1;bNULLdrop table if exists t1;create table t1 (b char(0) not null);create table if not exists t1 (b char(0) not null);Warnings:Note 1050 Table 't1' already existsinsert into t1 values (""),(null);Warnings:Warning 1048 Column 'b' cannot be nullselect * from t1;bdrop table t1;create table t1 (a int not null auto_increment,primary key (a)) engine=heap;drop table t1;create table t2 engine=heap select * from t1;ERROR 42S02: Table 'test.t1' doesn't existcreate table t2 select auto+1 from t1;ERROR 42S02: Table 'test.t1' doesn't existdrop table if exists t1,t2;Warnings:Note 1051 Unknown table 't1'Note 1051 Unknown table 't2'create table t1 (b char(0) not null, index(b));ERROR 42000: The used storage engine can't index column 'b'create table t1 (a int not null,b text) engine=heap;ERROR 42000: The used table type doesn't support BLOB/TEXT columnsdrop table if exists t1;Warnings:Note 1051 Unknown table 't1'create table t1 (ordid int(8) not null auto_increment, ord varchar(50) not null, primary key (ord,ordid)) engine=heap;ERROR 42000: Incorrect table definition; there can be only one auto column and it must be defined as a keycreate table not_existing_database.test (a int);ERROR 42000: Unknown database 'not_existing_database'create table `a/a` (a int);show create table `a/a`;Table Create Tablea/a CREATE TABLE `a/a` ( `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1create table t1 like `a/a`;drop table `a/a`;drop table `t1`;create table `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa int);ERROR 42000: Incorrect table name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'create table a (`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` int);ERROR 42000: Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too longcreate table t1 (a datetime default now());ERROR 42000: Invalid default value for 'a'create table t1 (a datetime on update now());ERROR HY000: Invalid ON UPDATE clause for 'a' columncreate table t1 (a int default 100 auto_increment);ERROR 42000: Invalid default value for 'a'create table t1 (a tinyint default 1000);ERROR 42000: Invalid default value for 'a'create table t1 (a varchar(5) default 'abcdef');ERROR 42000: Invalid default value for 'a'create table t1 (a varchar(5) default 'abcde');insert into t1 values();select * from t1;aabcdealter table t1 alter column a set default 'abcdef';ERROR 42000: Invalid default value for 'a'drop table t1;create table 1ea10 (1a20 int,1e int);insert into 1ea10 values(1,1);select 1ea10.1a20,1e+ 1e+10 from 1ea10;1a20 1e+ 1e+101 10000000001drop table 1ea10;create table t1 (t1.index int);drop table t1;drop database if exists mysqltest;Warnings:Note 1008 Can't drop database 'mysqltest'; database doesn't existcreate database mysqltest;create table mysqltest.$test1 (a$1 int, $b int, c$ int);insert into mysqltest.$test1 values (1,2,3);select a$1, $b, c$ from mysqltest.$test1;a$1 $b c$1 2 3create table mysqltest.test2$ (a int);drop table mysqltest.test2$;drop database mysqltest;create table `` (a int);ERROR 42000: Incorrect table name ''drop table if exists ``;ERROR 42000: Incorrect table name ''create table t1 (`` int);ERROR 42000: Incorrect column name ''create table t1 (i int, index `` (i));ERROR 42000: Incorrect index name ''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";id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t2 ref B B 21 const 1 Using whereselect * from t2 where b="world";a B3 worlddrop table t1,t2;create table t1(x varchar(50) );create table t2 select x from t1 where 1=2;describe t1;Field Type Null Key Default Extrax varchar(50) YES NULL describe t2;Field Type Null Key Default Extrax varchar(50) YES NULL 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;Field Type Null Key Default Extraa datetime NO 0000-00-00 00:00:00 b time NO 00:00:00 c date NO 0000-00-00 d int(3) NO 0 e decimal(3,1) NO 0.0 f bigint(19) NO 0 drop table t2;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;describe t2;Field Type Null Key Default Extrad date YES NULL t time YES NULL dt datetime YES NULL drop table t1,t2;create table t1 (a tinyint);create table t2 (a int) select * from t1;describe t1;Field Type Null Key Default Extraa tinyint(4) YES NULL describe t2;Field Type Null Key Default Extraa int(11) YES NULL drop table if exists t2;create table t2 (a int, a float) select * from t1;ERROR 42S21: Duplicate column name 'a'drop table if exists t2;Warnings:Note 1051 Unknown table 't2'create table t2 (a int) select a as b, a+1 as b from t1;ERROR 42S21: Duplicate column name 'b'drop table if exists t2;Warnings:Note 1051 Unknown table 't2'create table t2 (b int) select a as b, a+1 as b from t1;ERROR 42S21: Duplicate column name 'b'drop table if exists t1,t2;Warnings:Note 1051 Unknown table 't2'CREATE TABLE t1 (a int not null);INSERT INTO t1 values (1),(2),(1);CREATE TABLE t2 (primary key(a)) SELECT * FROM t1;ERROR 23000: Duplicate entry '1' for key 1SELECT * from t2;ERROR 42S02: Table 'test.t2' doesn't existDROP TABLE t1;DROP TABLE IF EXISTS t2;Warnings:Note 1051 Unknown table 't2'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;Table Create Tablet1 CREATE TABLE `t1` ( `a` int(11) NOT NULL, `b` int(11) default NULL, PRIMARY KEY (`a`), KEY `b` (`b`), KEY `b_2` (`b`), KEY `b_3` (`b`), KEY `b_4` (`b`), KEY `b_5` (`b`), KEY `b_6` (`b`), KEY `b_7` (`b`), KEY `b_8` (`b`), KEY `b_9` (`b`), KEY `b_10` (`b`), KEY `b_11` (`b`), KEY `b_12` (`b`), KEY `b_13` (`b`), KEY `b_14` (`b`), KEY `b_15` (`b`), KEY `b_16` (`b`), KEY `b_17` (`b`), KEY `b_18` (`b`), KEY `b_19` (`b`), KEY `b_20` (`b`), KEY `b_21` (`b`), KEY `b_22` (`b`), KEY `b_23` (`b`), KEY `b_24` (`b`), KEY `b_25` (`b`), KEY `b_26` (`b`), KEY `b_27` (`b`), KEY `b_28` (`b`), KEY `b_29` (`b`), KEY `b_30` (`b`), KEY `b_31` (`b`)) ENGINE=MyISAM DEFAULT CHARSET=latin1drop table t1;create table t1 select if(1,'1','0'), month("2002-08-02");drop table t1;create table t1 select if('2002'='2002','Y','N');select * from t1;if('2002'='2002','Y','N')Ydrop table if exists t1;SET SESSION storage_engine="heap";SELECT @@storage_engine;@@storage_engineMEMORYCREATE TABLE t1 (a int not null);show create table t1;Table Create Tablet1 CREATE TABLE `t1` ( `a` int(11) NOT NULL) ENGINE=MEMORY DEFAULT CHARSET=latin1drop table t1;SET SESSION storage_engine="gemini";ERROR 42000: Unknown table engine 'gemini'SELECT @@storage_engine;@@storage_engineMEMORYCREATE TABLE t1 (a int not null);show create table t1;Table Create Tablet1 CREATE TABLE `t1` ( `a` int(11) NOT NULL) ENGINE=MEMORY DEFAULT CHARSET=latin1SET SESSION storage_engine=default;drop table t1;create table t1 ( k1 varchar(2), k2 int, primary key(k1,k2));insert into t1 values ("a", 1), ("b", 2);insert into t1 values ("c", NULL);ERROR 23000: Column 'k2' cannot be nullinsert into t1 values (NULL, 3);ERROR 23000: Column 'k1' cannot be nullinsert into t1 values (NULL, NULL);ERROR 23000: Column 'k1' cannot be nulldrop table t1;create table t1 select x'4132';drop table t1;create table t1 select 1,2,3;create table if not exists t1 select 1,2;Warnings:Note 1050 Table 't1' already existscreate table if not exists t1 select 1,2,3,4;ERROR 21S01: Column count doesn't match value count at row 1create table if not exists t1 select 1;Warnings:Note 1050 Table 't1' already existsselect * from t1;1 2 31 2 30 1 20 0 1drop table t1;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;Warnings:Note 1050 Table 't1' already existsWarning 1364 Field 'a' doesn't have a default valueselect * from t1;a b1 10 2create table if not exists t1 select 3 as 'a',4 as 'b';Warnings:Note 1050 Table 't1' already existscreate table if not exists t1 select 3 as 'a',3 as 'b';ERROR 23000: Duplicate entry '3' for key 1select * from t1;a b1 10 23 4drop table t1;create table `t1 `(a int);ERROR 42000: Incorrect table name 't1 'create database `db1 `;ERROR 42000: Incorrect database name 'db1 'create table t1(`a ` int);ERROR 42000: Incorrect column name 'a 'create table t1 (a int,);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 ')' at line 1create table t1 (a int,,b int);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 'b int)' at line 1create table t1 (,b int);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 'b int)' at line 1create table t1 (a int, key(a));create table t2 (b int, foreign key(b) references t1(a), key(b));drop table if exists t1,t2;create table t1(id int not null, name char(20));insert into t1 values(10,'mysql'),(20,'monty- the creator');create table t2(id int not null);insert into t2 values(10),(20);create table t3 like t1;show create table t3;Table Create Tablet3 CREATE TABLE `t3` ( `id` int(11) NOT NULL, `name` char(20) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1select * from t3;id namecreate table if not exists t3 like t1;Warnings:Note 1050 Table 't3' already existsselect @@warning_count;@@warning_count1create temporary table t3 like t2;show create table t3;Table Create Tablet3 CREATE TEMPORARY TABLE `t3` ( `id` int(11) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1select * from t3;iddrop table t3;show create table t3;Table Create Tablet3 CREATE TABLE `t3` ( `id` int(11) NOT NULL, `name` char(20) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1select * from t3;id namedrop table t2, t3;create database mysqltest;create table mysqltest.t3 like t1;create temporary table t3 like mysqltest.t3;show create table t3;Table Create Tablet3 CREATE TEMPORARY TABLE `t3` ( `id` int(11) NOT NULL, `name` char(20) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1create table t2 like t3;show create table t2;Table Create Tablet2 CREATE TABLE `t2` ( `id` int(11) NOT NULL, `name` char(20) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1select * from t2;id namecreate table t3 like t1;create table t3 like mysqltest.t3;ERROR 42S01: Table 't3' already existscreate table non_existing_database.t1 like t1;ERROR 42000: Unknown database 'non_existing_database'create table t3 like non_existing_table;ERROR 42S02: Unknown table 'non_existing_table'create temporary table t3 like t1;ERROR 42S01: Table 't3' already existsdrop table t1, t2, t3;drop table t3;drop database mysqltest;SET SESSION storage_engine="heap";SELECT @@storage_engine;@@storage_engineMEMORYCREATE TABLE t1 (a int not null);show create table t1;Table Create Tablet1 CREATE TABLE `t1` ( `a` int(11) NOT NULL) ENGINE=MEMORY DEFAULT CHARSET=latin1drop table t1;SET SESSION storage_engine="gemini";ERROR 42000: Unknown table engine 'gemini'SELECT @@storage_engine;@@storage_engineMEMORY
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -