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 ...
随机推荐
- GB2312简体中文编码表
GB2312简体中文编码表 code +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F A1A0 . . · ˉ ˇ ¨ " 々 — - | … ...
- 一些LR的经验,讲的还不错
https://blog.csdn.net/Dinosoft/article/details/50492309 记录一下.
- c++学习之多态(虚函数和纯虚函数)
c++是面向对象语言,面向对象有个重要特点,就是继承和多态.继承之前学过了,就是一种重用类的设计方式.原有的类叫父类,或者基类,继承父类的类叫子类.在设计模式中,我们总是要避免继承,推荐用组合.因为继 ...
- Backup and restore of FAST Search for SharePoint 2010
一个同事问我一个问题: 如果FAST Search for SharePoint 2010被full restore到了一个之前的时间点, 那么当FAST Search重新开始一个增量爬网的时候, 会 ...
- Ubuntu挂载samba共享目录
Ubuntu中现在没有smbfs了,所以smbmount命令也用不了了,现在可以使用mount.cifs命令来挂载. Usage: mount.cifs <remotetarget> & ...
- TeamTalk 5
TeamTalk 5 Repository for TeamTalk 5 development. Download TeamTalk 5 SDK To build the TeamTalk clie ...
- C++ 之 基础回顾(一)
1 exe 程序
- 总结一些Android好用的开源库
1.android-viewFlow https://github.com/pakerfeldt/android-viewflow 2. android-viewbadger https://gith ...
- FFmpeg视频处理必备
http://ffmpeg.org/官网 A complete, cross-platform solution to record, convert and stream audio and vid ...
- AndroidStudio简单的apk混淆
打包APK又一个看起来难 却不难并且不可或缺的标配,为什么这样说呢?由于没有混淆,你的代码被别人反编译你的代码将像一个裸奔的人一样展示在别人的面前.你的APP的安全将得不到保证.Android搞的混淆 ...