【SQL篇章--CREATE TABLE】
CREATE TABLE t7(id INT ,NAME VARCHAR(20), PRIMARY KEY(`id`)) ENGINE=INNODB;
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name (create_definition,...) [table_options] [partition_options]
CREATE TABLE t7(id INT,TIME TIMESTAMP) AS SELECT id,TIME FROM t1 ;
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)] [table_options] [partition_options] [IGNORE | REPLACE] [AS] query_expression
CREATE TABLE t7 like t1;
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name { LIKE old_tbl_name | (LIKE old_tbl_name) }
CREATE TABLE t2 (blob_col BLOB, INDEX(blob_col(10)));
CREATE TABLE `t2` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`num` int(11) NOT NULL DEFAULT '0',
`logintime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE t2(
id INT NOT NULL AUTO_INCREMENT,
num INT NOT NULL DEFAULT 0,
logintime TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)ENGINE=INNODB AUTO_INCREMENT=100;
mysql> insert into t2(num) values(1);
Query OK, 1 row affected (0.12 sec) mysql> insert into t2(num) values(2);
Query OK, 1 row affected (0.01 sec)
mysql> select * from t2;
+-----+-----+---------------------+
| id | num | logintime |
+-----+-----+---------------------+
| 100 | 1 | 2016-11-16 14:45:20 |
| | 2 | 2016-11-16 14:45:25 |
+-----+-----+---------------------+
2 rows in set (0.00 sec)
mysql> show variables like '%auto_inc%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 1 |
| auto_increment_offset | 1 |
+--------------------------+-------+
CREATE TABLE t4(
id INT NOT NULL AUTO_INCREMENT COMMENT '序列号',
num INT NOT NULL DEFAULT 0 COMMENT '电话号码',
logintime TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '登录时间',
PRIMARY KEY (`id`)
)ENGINE=INNODB AUTO_INCREMENT=100 ;
mysql> show full columns from t4;
+-----------+-----------+-----------+------+-----+-------------------+----------------+---------------------------------+--------------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+-----------+-----------+-----------+------+-----+-------------------+----------------+---------------------------------+--------------+
| id | int(11) | NULL | NO | PRI | NULL | auto_increment | select,insert,update,references | 序列号 |
| num | int(11) | NULL | NO | | 0 | | select,insert,update,references | 电话号码 |
| logintime | timestamp | NULL | NO | | CURRENT_TIMESTAMP | | select,insert,update,references | 登录时间 |
+-----------+-----------+-----------+------+-----+-------------------+----------------+---------------------------------+--------------+
3 rows in set (0.00 sec)
- 一般用于NDB表的个别列。
- FIXED:指定固定的列宽度
- DYNAMIC:指定可变列宽度
- DEFAULT:两者都可用,根据列类型自动选择。
- 对于NDB表,COLUMN_FORMAT是:DEFAULT.对于非NDB引擎表是没有效果的,MySQL5.6之后,默认不开启。STORAGE
CREATE TABLE t5 (
c1 INT STORAGE DISK,
c2 INT STORAGE MEMORY
) ENGINE NDB; CREATE TABLE t1 (
c1 INT STORAGE DISK,
c2 INT STORAGE MEMORY
) TABLESPACE ts_1 ENGINE NDB;
CREATE TABLE new_tbl LIKE orig_tbl;
create table t4 like t2;
mysql> desc t2;
+-----------+-----------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-----------+------+-----+-------------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| num | int(11) | NO | | 0 | |
| logintime | timestamp | NO | | CURRENT_TIMESTAMP | |
+-----------+-----------+------+-----+-------------------+----------------+
mysql> desc t4;
+-----------+-----------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-----------+------+-----+-------------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| num | int(11) | NO | | 0 | |
| logintime | timestamp | NO | | CURRENT_TIMESTAMP | |
+-----------+-----------+------+-----+-------------------+----------------+
CREATE TABLE new_tbl [AS] SELECT * FROM orig_tbl;
mysql> desc s1;
+---------+-------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+-------------------+-------+
| id | int(11) | NO | PRI | NULL | |
| name | varchar(20) | YES | | NULL | |
| LogTime | timestamp | YES | | CURRENT_TIMESTAMP | |
+---------+-------------+------+-----+-------------------+-------+
mysql> select * from s1;
+----+------+---------------------+
| id | name | LogTime |
+----+------+---------------------+
| 1 | kata | 2016-11-16 16:01:48 |
+----+------+---------------------+
create table s2 as select * from s1;
mysql> desc s2;
+---------+-------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+-------------------+-------+
| id | int(11) | NO | | NULL | |
| name | varchar(20) | YES | | NULL | |
| LogTime | timestamp | YES | | CURRENT_TIMESTAMP | |
+---------+-------------+------+-----+-------------------+-------+
mysql> select * FROM s2;
+----+------+---------------------+
| id | name | LogTime |
+----+------+---------------------+
| 1 | kata | 2016-11-16 16:01:48 |
+----+------+---------------------+
create table s3 as select id,name from s2;
mysql> desc s3;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | NO | | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
mysql> select * from s3;
+----+------+
| id | name |
+----+------+
| 1 | kata |
+----+------+
create table s4(Sid int,Sname varchar(10)) as select id as 'Sid',name as 'Sname' from s1;
mysql> desc s4;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| Sid | int(11) | YES | | NULL | |
| Sname | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
创建表时指定的列名:前后不一致时:结果异常
mysql> create table s7(Sid int,Sname varchar(10)) as select id,name from s1;
异常结果:
mysql> desc s7;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| Sid | int(11) | YES | | NULL | |
| Sname | varchar(10) | YES | | NULL | |
| id | int(11) | NO | | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
| File | Purpose |
| tbl_name.frm | Table format (definition) file |
| tbl_name.MYD | Data file |
| tbl_name.MYI | Index file |
【SQL篇章--CREATE TABLE】的更多相关文章
- SQL Server: create table sql script
---摇奖observeh数据库设计 Function getSpace lottery /* -- Author:geovindu 涂聚文 -- Date: 20180427 为了自写生成代码.根据 ...
- linux之SQL语句简明教程---CREATE TABLE
表格是数据库中储存资料的基本架构.在绝大部份的情况下,数据库厂商不可能知道您需要如何储存您的资料,所以通常您会需要自己在数据库中建立表格.虽然许多数据库工具可以让您在不需用到 SQL 的情况下建立表格 ...
- MySQL Create Table创建表
表的创建命令需要: 表的名称 字段名称 定义每个字段(类型.长度等) 语法 下面是通用的SQL语法用来创建MySQL表: CREATE TABLE table_name (column_name co ...
- SQL CREATE TABLE 语句\SQL 约束 (Constraints)\SQL NOT NULL 约束\SQL UNIQUE 约束
CREATE TABLE 语句 CREATE TABLE 语句用于创建数据库中的表. SQL CREATE TABLE 语法 CREATE TABLE 表名称 ( 列名称1 数据类型, 列名称2 数据 ...
- 【SQL篇章】【SQL语句梳理 :--基于MySQL5.6】【已梳理:ALTER TABLE解析】
ALTER TABLE 解析实例: SQL: 1.增加列 2.增加列,调整列顺序 3.增加索引 4.增加约束 5.增加全文索引FULL-TEXT 6.改变列的默认值 7.改变列名字(类型,顺序) 8. ...
- php大力力 [023节]CREATE TABLE创建新表sql写字段备注(2015-08-27)
2015-08-27 php大力力023.CREATE TABLE创建新表sql写字段备注 http://www.cnblogs.com/dalitongxue/p/4762182.html 参考: ...
- SQL CREATE TABLE 语句
CREATE TABLE 语句 CREATE TABLE 语句用于创建数据库中的表. SQL CREATE TABLE 语法 CREATE TABLE 表名称 ( 列名称1 数据类型, 列名称2 数据 ...
- MySQL 列,可选择的数据类型(通过sql命令查看:`help create table;`)
MySQL 列,可选择的数据类型(通过sql命令查看:help create table;) BIT[(length)] | TINYINT[(length)] [UNSIGNED] [ZEROFIL ...
- 转换sql文件的create table语句为drop table语句
package com.csii.pweb.query.action; import java.io.BufferedReader; import java.io.FileNotFoundExcept ...
随机推荐
- jquery属性选择器(同时匹配多个条件)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- mysql存储过程中的异常处理
http://www.cnblogs.com/cookiehu/p/4994278.html 定义异常捕获类型及处理方法: DECLARE handler_action HANDLER FOR con ...
- FireMonkey 导出目前 Style 另存文件
FireMonkey 能将目前使用的 Style 导出成文件,它提供二种文件格式,请看下列代码: *.style procedure TForm1.Button1Click(Sender: TObje ...
- 从钉钉微应用定制化导航栏看如何实现Hydrid App开发框架
钉钉是阿里的一款企业应用APP,里面提供了混合微应用的SDK,这其实最好的一种APP架构模式.微信公众号浏览器JSSDK也提供了类似功能特性,在在交互性上没有钉钉深入. http://ddtalk.g ...
- Eclipse的SVN插件下载
Links for 1.8.x Release:Eclipse update site URL: http://subclipse.tigris.org/update_1.8.xsvn插件包下载: h ...
- InfluxDB学习之InfluxDB的HTTP API写入操作
HTTP API也有两种操作:写入和查询,本文就先给大家介绍一下 InfluxDB的HTTP API的写入操作方式. 在InfluxDB学习的上一篇文章:InfluxDB学习之InfluxDB ...
- Maven+SSM框架实现简单的增删改查
Spring介绍: spring 使用基本的 JavaBean 来完成以前只可能由 EJB 完成的事情.然而, Spring的用途不仅限于服务器端的开发.从简单性.可测试性和松耦合的角度而言,任何Ja ...
- Android总结篇系列:Android Service
Service通常总是称之为“后台服务”,其中“后台”一词是相对于前台而言的,具体是指其本身的运行并不依赖于用户可视的UI界面,因此,从实际业务需求上来理解,Service的适用场景应该具备以下条件: ...
- Java程序运行时,数据都保存到什么地方?
程序运行时,我们最好对数据保存到什么地方做到心中有数.特别要注意的是内存的分配.有六个地方都可以保存数据: 寄存器 这是最快的保存区域,因为它位于和其他所有保存方式不同的地方:处理器内部.然而,寄存器 ...
- C#实现通过Gzip来对数据进行压缩和解压
C#实现通过Gzip来对数据进行压缩和解压 internal static byte[] Compress(byte[] data) { using (var compressedStream = n ...