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 ...
随机推荐
- 实施CMMI3的体会
公司从去年年底开始实施CMMI3,记得当初上培训课的时候,听着老师介绍过程管理,项目管理,工程过程,支持过程这四大类过程域的时候,全部门上下听得稀里糊涂,从未想到这个鬼东西还这么复杂,这么麻烦. 公司 ...
- 关于如何在你的Web项目中实现对空间数据访问权限的控制(一)
Wednesday, 23 JUNE 近来一直在研究关于如何在我的WebGIS项目中实现对空间数据(已发布在GeoServer上)进行权限管理的问题.虽然到目前为止没能找到一个完美的解决方案,但通过这 ...
- 在flask中使用jsonify和json.dumps的区别
转载:https://blog.csdn.net/Duke_Huan_of_Qi/article/details/76064225
- Could not connect to Redis at 192.168.0.129:6379: Connection refused
在虚拟机上(CentOS 6.7)本机连接自己的redis [root@localhost bin]# ./redis-cli -h Could not connect to Redis at : C ...
- unity 统一替换shader
camera.SetReplacementShader(shader,"tag"); 可以切了测试性能
- [Python爬虫] 之六:Selenium 常用控件用法
Selenium 常用控件用法 1.文本框 上图中,如何定位搜索文本框,并输入搜索内容进行搜索 首先:利用方法 find_element_by_xpath定位元素:inputElements = se ...
- Linux挂载命令mount用法及参数详解
导读 mount是Linux下的一个命令,它可以将分区挂接到Linux的一个文件夹下,从而将分区和该目录联系起来,因此我们只要访问这个文件夹,就相当于访问该分区了. 挂接命令(mount) 首先,介绍 ...
- html5-video视频播放
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...
- (剑指Offer)面试题50:树中两个结点的最低公共祖先
题目: 求树中两个结点的最低公共祖先 思路: 考虑一下几种情况: 1.该树为二叉搜索树 二叉搜索树是排序树,位于左子树点的结点都比父结点小,而位于右子树的结点都比父结点大,只需要从树的根结点开始和两个 ...
- HDU 1710 Binary Tree Traversals(二叉树)
题目地址:HDU 1710 已知二叉树先序和中序求后序. #include <stdio.h> #include <string.h> int a[1001], cnt; ty ...