语法:
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 比较的更多相关文章

  1. [Hive - LanguageManual] Create/Drop/Alter Database Create/Drop/Truncate Table

    Hive Data Definition Language Hive Data Definition Language Overview Create/Drop/Alter Database Crea ...

  2. 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 ...

  3. create table as 和create table like的区别

    create table as 和create table like的区别 对于MySQL的复制相同表结构方法,有create table as 和create table like 两种,区别是什么 ...

  4. 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 ...

  5. iview之——table中嵌套input、select等

    使用iview在table中嵌入button是比较常见的需求,但是在table中嵌入input或者select你是否考虑过呢?本文用实例介绍input和select在table中的嵌套. 理解tabl ...

  6. 错误提示 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 ...

  7. 【转载】alter table move 和 alter table shrink space的区别

    move 和shrink 的共同点1.收缩段2.消除部分行迁移3.消除空间碎片4.使数据更紧密 shrink 语法:  alter table TABLE_NAME shrink space [com ...

  8. 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. ...

  9. 通过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 ...

  10. 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 ...

随机推荐

  1. linux下svn的用法

    转载:http://blog.chinaunix.net/uid-22150747-id-189264.html 1.将文件checkout到本地目录 svn checkout path(path是服 ...

  2. Unity 面试题

    一:什么是协同程序? 在主线程运行的同时开启另一段逻辑处理,来协助当前程序的执行,协程很像多线程,但是不是多线程,Unity的协程实在每帧结束之后去检测yield的条件是否满足. 二:Unity3d中 ...

  3. 【java】弃用System.out.println(),迎接log

    展示性能差异: 1.System.out.println()输出 package com.sxd.swapping.test; import org.junit.Test; public class ...

  4. unity3d-地图制作之暗光

    最近看了暗黑破坏神3的视频,看到游戏里面的场景画面,颇有感触. 画面可谓做的极好的,虽然我审美观不是那么滴好,但是这游戏就让我看的赏心悦目,就让我好想来撸那么一把. 看完暗黑视频后,我就开始研究里面的 ...

  5. MsChart<3> 饼状图

    MsChart,饼状图 1 <asp:Chart ID="Chart1" runat="server" BorderlineDashStyle=" ...

  6. Apache+Tomcat负载均衡问题集锦

    之前在windows 环境下搭建了下apache+tomcat负载均衡(不会的能够參考之前的文档,文档对于linux和windows都适用),一帆风顺.没有出现不论什么问题.今天尝试着在linux下搭 ...

  7. 跨平台app开发(引擎)工具的选择

    1.html5执行速度慢,用户体验不好 2.原生应用开发,即ios和安卓分别开发,需要两种技术人员,后期代码维护困难,很难达到统一. 3.xamarin是一款c#的解决方案,收费.xamarin.fo ...

  8. EasyUI datagrid 明细表格中编辑框 事件绑定 及灵活计算 可根据此思路 扩展其他

    原创 : EasyUI datagrid 明细表格中编辑框 事件绑定 及灵活计算 可根据此思路 扩展其他 转载,请注明出处哦!谢谢! 原创 : EasyUI datagrid 明细表格中编辑框 事件绑 ...

  9. JVM垃圾回收(GC)整理总结学习

    基本回收算法 1. 引用计数(Reference Counting)比较古老的回收算法.原理是此对象有一个引用,即增加一个计数,删除一个引用则减少一个计数.垃圾回收时,只用收集计数为0的对象.此算法最 ...

  10. 多个Mapper和Reducer的Job

    多个Mapper和Reducer的Job @(Hadoop) 对于复杂的mr任务来说,只有一个map和reduce往往是不能够满足任务需求的,有可能是需要n个map之后进行reduce,reduce之 ...