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)

  

----

最新文章

  1. POJ2774 Long Long Message [后缀数组]
  2. Extjs.Button 按钮
  3. Excel 自动更正
  4. 树状sql--采用递归方式获取节点
  5. anr产生的原理&如何避免(android)
  6. 何时要打开stm32的AFIO时钟
  7. (转载)js----对象直接量
  8. 在Xcode中使用Clang Format
  9. AC自动机模板2(【CJOJ1435】)
  10. NodeJs实现自定义分享功能,获取微信授权+用户信息
  11. Linux 虚存 linux2.6内核特性
  12. Android简易实战教程--第一话《最简单的计算器》
  13. 巡风源码阅读与分析--querylogic函数
  14. 如何设置C-Lodop打印控件的端口
  15. Node.js简述
  16. 操作系统笔记(六)页面置换算法 FIFO法 LRU最近最久未使用法 CLOCK法 二次机会法
  17. SSM(Spring+SpringMVC+Mybatis)框架环境搭建(整合步骤)(一)
  18. 微信小程序 发现之旅(三)—— 组件之间的参数传递
  19. c++字节数组转换为整型
  20. centos 7 网站前端中文乱码分析、解决办法

热门文章

  1. Apache下error.log文件太大的处理
  2. 7款Flash和Javascript网页视频播放器
  3. .NET:命令行解析器介绍
  4. 用C#调用Windows API向指定窗口发送按键消息 z
  5. OpenShift负载分区策略(Router Shading)
  6. UltraISO制作ISO镜像文件
  7. 测试markdown 博客功能
  8. go语言基础之输入的使用
  9. vmware 传输(vmdb)错误-32:pipe:read failed 解决方法
  10. Mysql导出逗号分隔的csv文件