语法:
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. Eclipse 平台Java项目文件结构

  2. SpringBoot添加支持CORS跨域访问

    原文:https://www.jianshu.com/p/c6ea21b64f6e CORS(Cross-Origin Resource Sharing)"跨域资源共享",是一个W ...

  3. 【资料】wod强壮护符

    泛用耗材 损坏的 卡罗先活力护符 小型的 强壮护符 改良的 鲁比斯护符   否定护符   活跃护符   自然防御护符   防御疾病护符 特定职业使用耗材护符 野蛮人 诗人 祭司 泛用 仪式用巴博许教的 ...

  4. MyEclipse for Linux版下载

    最近看到很多网友都在找MyEclipse for Linux版下载,费了很大劲也没有找到.1.建议通过代理到官方网站下载. 2.用迅雷下载.设置迅雷使用代理下载(我用的就是这种方式). MyEclip ...

  5. 将Maven2项目转为MyEclipse项目

    现在项目中,大家开始用jetty.它不用像在MyEclipse中使用Tomcat那样要部署,也不用像在Tomcat中那样,要把应用都放到webapp文件夹下.jetty可以直接用你的项目的目录结构. ...

  6. Qt 串口类QSerialPort 使用笔记

    Qt 串口类QSerialPort 使用笔记 虽然现在大多数的家用PC机上已经不提供RS232接口了.但是由于RS232串口操作简单.通讯可靠,在工业领域中仍然有大量的应用.Qt以前的版本中,没有提供 ...

  7. IP数字,数字IP

    DECLARE @ip VARCHAR(60)='113.118.138.159'DECLARE @ip_int BIGINT=[dbo].[f_IP2Int](@ip) SELECT [IPstar ...

  8. 使用Intellij加载Spark源代码

    如何使用Intellij加载Spark源代码 转载注明原文http://www.cnblogs.com/shenh062326/p/6189643.html 查看Spark源代码或修改Spark源代码 ...

  9. 在div 底部显示背景图片

    下面代码实现div层背景图片在底部显示: div { background : url (/images/bg.jpg) no-repeat fixed ; background-position-y ...

  10. Android媒体扫描详细解析之二(MediaScanner & MediaProvider)

    上篇blog说到了经过对文件夹进行扫描如果后缀符合系统设定的一些格式,那么就会进行文件内容扫描下面我们紧接着STEP 14中的 status_t StagefrightMediaScanner::pr ...