create table 可以分成三类

一、一般create table 语句

  1  语法

create [temporary] table [if not exists] tbl_name
(create_definition)
[table_options]
[parttion_options]

  2  例子:创建一个person表它包涵id,name,birthday这几个列

create table person(id int not null auto_increment,
name varchar(8),
birthday datetime,
constraint pk__person primary key(id));

二、create table like 参照已有表的定义,来定义新的表

  1  语法  

create [temporary] table [if not exists] tbl_name
{like old_tbl_name | (like old_tbl_name)};

  2  例子:定义一个person_like 表,它的表结构参照上面例子中的person表

mysql> create table person_like like person;
Query OK, 0 rows affected (0.01 sec) mysql> show create table person_like \G
*************************** 1. row ***************************
Table: person_like
Create Table: CREATE TABLE `person_like` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(8) DEFAULT NULL,
`birthday` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

  可以看出使用create table like 方式创建的表,它的表结构和原表是一样的。

三、根据select 的结果集来创建表

  1  语法

create [temporary] table [if not exists] tbl_name
[(create_definition,...)]
[table_options]
[partition_options]
[ignore | replace]
[as] query_expression

  2  例子:

mysql> create table person_as
-> as
-> select id,name from person;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> show create table person_as \G
*************************** 1. row ***************************
Table: person_as
Create Table: CREATE TABLE `person_as` (
`id` int(11) NOT NULL DEFAULT '',
`name` varchar(8) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

  

----

mysql create table 语法详解的更多相关文章

  1. MySQL create table语法详解

    前面在查建表时key和index的区别时,发现建表语句包含了太多信息,于是完整看看官方手册的这一小节. 该文章根据MySQL 5.7的手册作笔记,而MySQL 8.0该节地址如下: https://d ...

  2. Oracle创建表语句(Create table)语法详解及示例

    创建表(Create table)语法详解1. ORACLE常用的字段类型ORACLE常用的字段类型有VARCHAR2 (size) 可变长度的字符串, 必须规定长度CHAR(size) 固定长度的字 ...

  3. Oracle创建表语句(Create table)语法详解及示例、、 C# 调用Oracle 存储过程返回数据集 实例

    Oracle创建表语句(Create table)语法详解及示例 2010-06-28 13:59:13|  分类: Oracle PL/SQL|字号 订阅 创建表(Create table)语法详解 ...

  4. mysql create dabase 语法详解

    由于SQL标准的存在,各个关系型数据库管理系统中创建库的语句都差不多 一.mysql 中创建数据库的语法如下: 1.创建数据库的语法: create {database | schema } [if ...

  5. MySQL create table 语法

    MySQL中create table语句的基本语法是: CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name     [(create_definitio ...

  6. MySQL create table语法中的key与index的区别

    在create table的语句中,key和index混淆在一起,官方手册中的解释是这样: KEY is normally a synonym for INDEX. The key attribute ...

  7. Mysql数据库查询语法详解

    数据库的完整查询语法 在平常的工作中经常需要与数据库打交道 , 虽然大多时间都是简单的查询抑或使用框架封装好的ORM的查询方法 , 但是还是要对数据库的完整查询语法做一个加深理解 数据库完整查询语法框 ...

  8. mysql用户授权、数据库权限管理、sql语法详解

    mysql用户授权.数据库权限管理.sql语法详解 —— NiceCui 某个数据库所有的权限 ALL 后面+ PRIVILEGES SQL 某个数据库 特定的权限SQL mysql 授权语法 SQL ...

  9. mysql CREATE TABLE语句 语法

    mysql CREATE TABLE语句 语法 作用:创建数据库中的表. 大理石量具系列 语法:CREATE TABLE 表名称 (列名称1 数据类型,列名称2 数据类型,列名称3 数据类型,.... ...

随机推荐

  1. set bin 集合

    set: create table rr(zz char(4));create table test5 (rr set('美丽','态度好','温柔','善良'));insert into test5 ...

  2. Python continue 语句

    Python continue 语句 Python continue 语句跳出本次循环,而break跳出整个循环. continue 语句用来告诉Python跳过当前循环的剩余语句,然后继续进行下一轮 ...

  3. End of Life check fails with NullPointerException

    Checks if the running version of JIRA is approaching, or has reached End of Life. Details Type: Bug ...

  4. Jacob的使用出错总结

    转自:http://blog.163.com/wm_at163/blog/static/13217349020114166447941/ Jacob的使用方法: 1.在工程中导入 jacob.jar ...

  5. 数学图形(2.7)sphere sine wave

    在球上以SIN曲线的轨迹游走. #http://www.mathcurve.com/courbes3d/couronnetangentoidale/couronnetangentoidale.shtm ...

  6. C/C++ 中头文件相互包含引发的问题

    转自:http://blog.csdn.net/hazir/article/details/38600419 今天下午遇到一个头文件相互包含而导致的编译问题,花了我不少时间去调试没找到问题,最后晚上跟 ...

  7. SASS详解之编译输出的样式

    SASS是一种CSS预处理语言,没有装环境的话是不能被解析的.但是有了koala编译工具之后,解析SASS不需要环境也毫无压力了.SASS的输出格式有四种:嵌套.扩大.紧凑和压缩.下面结合小例子为大家 ...

  8. [ES6] 04. The let keyword -- 2 Fiald case

    Fiald case 1: let can work in it's block { let a = 10; var b = 1; } a // ReferenceError: a is not de ...

  9. 微信小程序 - wx:key

    看官方源码以及代码示例: 示例官网:列表渲染wx:key 官方原话 如果列表中项目的位置会动态改变或者有新的项目添加到列表中,并且希望列表中的项目保持自己的特征和状态(如 <input/> ...

  10. ScriptableObject 对象化的运用

    http://www.cnblogs.com/oldman/articles/2409554.html using UnityEngine; using UnityEditor; using Syst ...