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 ...
随机推荐
- 解决 Operation must use an updateable query
在asp.net 开发环境下,用jet 4.0连接access数据库, 有时会产生Operation must use an updateable query,这是由于相关用户mdb文件没有Modif ...
- crtmpserver配置文件详解
Configuration file配置文件 The configuration file is actually a lua script which must contain an object ...
- Tor Browser(洋葱浏览器)——一款使你匿名上网的浏览器
第一次知道Tor是在有关斯诺登的新闻报道中. 简单说Tor是一款是你匿名访问网络的的软件.用户通过Tor可以在因特网上进行匿名交流. 为了实现匿名目的,Tor把分散在全球的计算机集合起来形成一个加密回 ...
- 无线AP和无线路由器区别wifi热点
转自:http://network.51cto.com/art/201310/413327.htm 就像很多用户很容易混淆无线上网卡和无线网卡一样,很多用户也分不清无线AP和无线路由,小峰便是其中的一 ...
- The application’s PagerAdapter changed the adapter’s contents without calling PagerAdapter#notifyDa
错误原因是在于修改了PageAdapter,却没有调用 PageAdapter的nodifyDataSetChanged方法.注意刷新数据 需要在主线程. 今天在做项目时出现了这个问题,一直报没有调用 ...
- 更改Thunderbird的默认语言
使用的Thunderbird Poratable版本是英文的,可以用以下方式修改为中文界面: 1.下载中文语言包 在官方网站的https://addons.mozilla.org/en-US/thun ...
- Spring核心之IoC——依赖注入
在J2EE开发平台中,Spring是一种优秀的轻量级企业应用解决方案.Spring倡导一切从实际出发,它的核心技术就是IOC(控制反转)和AOP(面向切面编程)技术.本文用的Spring版本为spri ...
- Sqlite清空表数据
delete from TableName; //清空数据 where name ='TableName';//自增长ID为0
- 配置文件格式用哪个?文件夹+纯文本文件,XML,SQLite
稍具规模的软件都会须要一个配置文件来支持软件的执行.眼下常见的配置文件格式有纯文本.XML.SQLite.自己定义二进制格式,怎样进行选择呢? 1 纯文本--永远不会失效的文件格式 文本化是传统Uni ...
- Nubia Z5S官方4.4 UI2.0音频Audio部分简单分析(也适用于其它8974/8064机型)以及降低破音出现几率的方法
转载请注明出处和网址链接: http://blog.csdn.net/syhost/article/details/31419749 此篇本是在Z5S的官方4.4内測版出来时写的, 主要是看到其在au ...