create table like 和create table select 比较
语法:
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
[(create_definition,...)]
[table_options] [select_statement]
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
[(] LIKE old_tbl_name [)];
测试过程:
原数据表:
mysql> show create table test_order \G
*************************** 1. row ***************************
Table: test_order
Create Table: CREATE TABLE `test_order` (
`pay_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`origin` int(10) DEFAULT NULL,
`team_id` int(11) DEFAULT NULL,
`state` int(11) DEFAULT NULL,
KEY `team_id` (`team_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
mysql> create table cc select * from test_order;
Query OK, 9900 rows affected (0.11 sec)
Records: 9900 Duplicates: 0 Warnings: 0
mysql> create table dd like test_order;
Query OK, 0 rows affected (0.22 sec)
查看数据:
mysql> select * from cc limit 2;
+---------------------+--------+---------+-------+
| pay_time | origin | team_id | state |
+---------------------+--------+---------+-------+
| 2011-06-22 18:04:47 | 10 | 100 | 100 |
| 2011-06-22 18:04:47 | 10 | 100 | 101 |
+---------------------+--------+---------+-------+
2 rows in set (0.00 sec)
mysql> select * from dd;
Empty set (0.00 sec)
结果:cc表中数据与原表test_order中的一致,dd表中无数据
查看表结构:
mysql> show create table cc \G
*************************** 1. row ***************************
Table: cc
Create Table: CREATE TABLE `cc` (
`pay_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`origin` int(10) DEFAULT NULL,
`team_id` int(11) DEFAULT NULL,
`state` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
mysql> show create table dd \G
*************************** 1. row ***************************
Table: dd
Create Table: CREATE TABLE `dd` (
`pay_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`origin` int(10) DEFAULT NULL,
`team_id` int(11) DEFAULT NULL,
`state` int(11) DEFAULT NULL,
KEY `team_id` (`team_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
结果:cc表中,原表中的索引消失了;dd表与原表一致
结论:
create table select 会将原表中的数据完整复制一份,但表结构中的索引会丢失。
create table like 只会完整复制原表的建表语句,但不会复制数据
create table like 和create table select 比较的更多相关文章
- [Hive - LanguageManual] Create/Drop/Alter Database Create/Drop/Truncate Table
Hive Data Definition Language Hive Data Definition Language Overview Create/Drop/Alter Database Crea ...
- How to Quickly Create a Copy of a Table using Transact-SQL
The easiest way to create a copy of a table is to use a Transact-SQL command. Use SELECT INTO to ext ...
- create table as 和create table like的区别
create table as 和create table like的区别 对于MySQL的复制相同表结构方法,有create table as 和create table like 两种,区别是什么 ...
- jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the install tool.
jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the ...
- iview之——table中嵌套input、select等
使用iview在table中嵌入button是比较常见的需求,但是在table中嵌入input或者select你是否考虑过呢?本文用实例介绍input和select在table中的嵌套. 理解tabl ...
- 错误提示 Table '.***_ecms_news_data_' doesn't exist select keyid,dokey,newstempid,closepl,info
错误提示:Table '**.***_ecms_news_data_' doesn't exist select keyid,dokey,newstempid,closepl,infotags,wri ...
- 【转载】alter table move 和 alter table shrink space的区别
move 和shrink 的共同点1.收缩段2.消除部分行迁移3.消除空间碎片4.使数据更紧密 shrink 语法: alter table TABLE_NAME shrink space [com ...
- How To Convert A Partitioned Table To A Non-Partitioned Table Using DataPump In 11g (Doc ID 1276049.1)
How To Convert A Partitioned Table To A Non-Partitioned Table Using DataPump In 11g (Doc ID 1276049. ...
- 通过dbcp链接池对数据库操作报 Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)--解决方案
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for ...
- How To determine DDIC Check Table, Domain and Get Table Field Text Data For Value?
How To determineDDIC Check Table, Domain and Get Table Field Text Data For Value? 1.Get Table Fie ...
随机推荐
- Your first NHibernate based application
Welcome to NHibernate If you're reading this, we assume that you've just downloaded NHibernate and w ...
- Replace Pioneer 试用推广
Replace Pioneer: http://www.mind-pioneer.com 目前合法长期使用Replace Pioneer的唯一方法(除了购买之外): Replace Pioneer过期 ...
- linux下关于压缩、解压相关的操作
本文转自: http://alex09.iteye.com/blog/647128 很不错的linux下关于压缩.解压相关的操作,适合于linux初学者. .tar 解包:tar xvf Fil ...
- OpenCV Shi-Tomasi角点检测子
Shi-Tomasi角点检测子 目标 在这个教程中我们将涉及: 使用函数 goodFeaturesToTrack 来调用Shi-Tomasi方法检测角点. 理论 代码 这个教程的代码如下所示.源代码还 ...
- feedparser win7 python 安装
要获取订阅源读取当中的内容,Universal Feed Parser提供了非常多的API,这里说下详细的配置. 我的配置环境: win7 + python 2.7.5 步骤: 1.下载feedpar ...
- iOS:面向对象的思想使用sqlite数据库
SQLite支持的常见数据类型如下所示. –INTEGER 有符号的整数类型 –REAL 浮点类型 –TEXT 字符串类型,采用UTF-8和UTF-16字符编码 –BLOB 二进制大对象类型,能够存放 ...
- PowerDesigner教程系列(三)概念数据模型
目标: 本文主要介绍属性的标准检查约束.如何定义属性的附加检查. 一.定义属性的标准检查约束 标准检查约束是一组确保属性有效的表达式.在实体属性的特性窗口,打开如图所示的检查选项卡. 在这个选项卡可以 ...
- 测试markdown 博客功能
欢迎使用 Cmd - 在线 Markdown 编辑阅读器 我们理解您需要更便捷更高效的工具记录思想,整理笔记.知识,并将其中承载的价值传播给他人,Cmd Markdown 是我们给出的答案 -- 我们 ...
- php--session垃圾回收机制
在PHP中,没有任何变量指向这个对象时,这个对象就成为垃圾.PHP会将其在内存中销毁:这是PHP的GC垃圾处理机制,防止内存溢出. GC的工作就是扫描所有的Session信息,用当前时间减去sessi ...
- jdk1.7下载路径
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html