- 浏览: 272852 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (234)
- php (70)
- linux (46)
- apache (9)
- mysql (13)
- oauth (1)
- IT新闻 (18)
- 代码收藏 (20)
- python (2)
- webservice (6)
- 评论 (7)
- asd (0)
- 开源软件 (6)
- 前端 (9)
- 7z (1)
- js (17)
- windows (4)
- cmd (2)
- 开源 (3)
- vim (6)
- windows 软件安装错误 (2)
- 分享 (3)
- search (1)
- node.js (1)
- xmind (1)
- 变成语言 (1)
- drupal (0)
- jquery (2)
- css (7)
- ietester (1)
- 编辑器 (1)
- java (2)
- html5 (1)
- 生活 (1)
- Sublime Text 2 (1)
- 制图 (0)
- sublime (1)
最新评论
-
muxueqz:
我自己写了个开源的:http://muxueqz.top/sk ...
Delicious被Yahoo卖了 -
yangyongnihao:
...
REST与SOAP样式Web 服务的区别 -
wangshaofei:
zhou7707 写道 大神啊,太及时了,我今天服务器上不了 ...
Debian 6 下搭建nginx 1.3 -
zhou7707:
大神啊,太及时了,我今天服务器上不了外网,为搞包依赖折腾一 ...
Debian 6 下搭建nginx 1.3 -
wangshaofei:
bbs_ld 写道一楼说的对啊。如何解决呢?? 高手大人
利用php创建日期选择框
目的:测试create table a as select * from b 与create table a like b的区别
mysql
下测试:
源表:ti
表结构如下
root:test> show create table ti\G
*************************** 1. row ***************************
Table: ti
Create Table: CREATE TABLE `ti` (
`id` int(11) DEFAULT NULL,
`amount` decimal(7,2) DEFAULT NULL,
`m_photo_big` varchar(64) DEFAULT NULL,
`tr_date` date DEFAULT NULL,
`new_msg_flag` tinyint(4) NOT NULL DEFAULT '0',
`love_listreq` int(3) DEFAULT '1',
`love_listconfig` int(3) DEFAULT '1',
KEY `new_msg_flag` (`new_msg_flag`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
a 使用create as select语句创建表
root:test> create table ti2 as select * from ti limit 0;
Query OK, 0 rows affected (0.00 sec)
sroot:test> how create table ti2 ;
----------------------------
CREATE TABLE `ti2` (
`id` int(11) DEFAULT NULL,
`amount` decimal(7,2) DEFAULT NULL,
`m_photo_big` varchar(64) DEFAULT NULL,
`tr_date` date DEFAULT NULL,
`new_msg_flag` tinyint(4) NOT NULL DEFAULT '0',
`love_listreq` int(3) DEFAULT '1',
`love_listconfig` int(3) DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=latin1
对比源表的表结构,发现KEY `new_msg_flag` (`new_msg_flag`)没有被创建
b 使用like子句创建表
root:test> create table ti1 like ti;
Query OK, 0 rows affected (0.06 sec)
root:test> show create table ti1;
----------------------------------------
CREATE TABLE `ti1` (
`id` int(11) DEFAULT NULL,
`amount` decimal(7,2) DEFAULT NULL,
`m_photo_big` varchar(64) DEFAULT NULL,
`tr_date` date DEFAULT NULL,
`new_msg_flag` tinyint(4) NOT NULL DEFAULT '0',
`love_listreq` int(3) DEFAULT '1',
`love_listconfig` int(3) DEFAULT '1',
KEY `new_msg_flag` (`new_msg_flag`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
对比源表的表结构,两者完全一致,完整的包含了表结构和索引
结论:mysql下create table a as select * from b形式创建的表不包含索引信息,like子句形式包含完整表结构和索引信息
所以 as select 子句一般适用于建表并复制源表数据的情况,like子句适用于只复制表结构的情况
误用的风险: 索引的缺失对于业务的性能是致命的,不必多说.
Oracle
下:
a create as select同样不会创建索引
b oracle不支持like子句
权限不会随like一起复制
原表 test.test
原表table级别权限:
root:mysql> select * from tables_priv where Db='test' and Table_name='test';
+-------------+------+-------+------------+----------------+---------------------+-----------------------------+-------------+
| Host | Db | User | Table_name | Grantor | Timestamp | Table_priv | Column_priv |
+-------------+------+-------+------------+----------------+---------------------+-----------------------------+-------------+
| 192.168.%.% | test | root | test | root@localhost | 2009-09-17 11:22:25 | Select,Insert,Update,Delete | |
| 192.168.%.% | test | lidan | test | root@localhost | 2009-09-17 11:23:58 | Select,Insert,Update,Delete | |
+-------------+------+-------+------------+----------------+---------------------+-----------------------------+-------------+
2 rows in set (0.00 sec)
复制表:
root:test> create table pri_test like test;
Query OK, 0 rows affected (0.00 sec)
pri_test的权限
root:mysql> select * from tables_priv where Db='test' and Table_name='pri_test';
Empty set (0.00 sec)
可见使用like不可能保持原表和复制表的权限一致
至于如何实现完全创建表结构和索引的方法有待继续探讨!
发表评论
-
11111
2013-07-04 00:45 0qqqqqqqqqqqqq -
xcc
2013-06-24 17:41 0xxx -
征婚网站
2013-06-09 17:44 0征婚网站 -
CodeIgniter 用户指南 版本 2.1.3
2013-05-23 02:25 745CodeIgniter 是一套给 PHP 网站开发者使用的应用 ... -
xampp windows xdebug netbeans
2013-04-17 00:15 713xdebug config in php.ini xdeb ... -
Installing_Nginx_With_PHP5_And_MySQL_Support_On_Debian_Squeeze.rar
2013-03-17 20:37 613Installing_Nginx_With_PHP5_And_ ... -
Debian 6 下搭建nginx 1.3
2013-03-17 18:27 16401 准备debian 6.0环境 2 下载需要安装的 ... -
这样用google
2013-01-10 12:49 992美国人教你这样用Google,你真的会变特工!!!来源: ... -
NetBeans Hot Keys
2012-12-16 17:01 648最近使用netbeans,发现还不错NetBeans Hot ... -
drupal开发
2012-10-12 09:35 0在请求的url中获取回调函数,根据回调函数来判断页面显 ... -
php windows xp zip
2012-09-28 10:31 592php windows xp zip -
drupal7源码和文档
2012-09-19 08:00 596drupal7源码和文档 -
我的文件
2012-06-29 17:18 0阿道夫 -
Nginx + PHP5
2012-06-03 02:44 762WINDOWS下应该有PHP-FPM类 ... -
SSH的官方下载地址
2012-05-15 11:05 0这里分别是SSH的官方下载地址: Struts2.0: ... -
php文档
2012-05-11 10:34 675php文档。 -
php set_magic_quotes_runtime() 函数过时解决方法
2011-11-15 09:45 890tags标签: set_magic_quotes_runtim ... -
php静态方法调用非静态方法不可取
2011-11-08 15:22 2326那天对这个主题比较感 ... -
国外PHP老手谈为何放弃PHP而改用Python
2011-11-01 13:28 990本文作者做了11年的P ... -
vim 相关操作方法命令
2011-10-28 13:22 26251. 翻页 整页翻页 ctrl-f ctrl-b f就是f ...
相关推荐
本文分析了MySQL中create table as 与like的区别。分享给大家供大家参考,具体如下: 对于mysql的复制相同表结构方法,有create table as 和create table like 两种,区别是什么呢? 代码如下:create table t2 as ...
主要介绍了MySQL中表复制:create table like 与 create table as select,需要的朋友可以参考下
select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b 6、说明:外连接查询(表名1:a 表名2:b) select a.a, a.b, a.c, b.c, b.d, b.f from a ...
select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b 6、说明:外连接查询(表名1:a 表名2:b) select a.a, a.b, a.c, b.c, b.d, b.f from a ...
1. 复制表结构及其数据: 代码如下:create table table_name_new as select * from table_name_old2. 只复制表结构: 代码如下:create table table_name_new as select * from table_name_old where 1=2;或者: 代码...
CREATE TABLE 新表 SELECT * FROM 旧表 WHERE 1=2 或者 CREATE TABLE 新表 LIKE 旧表 2.复制表结构及数据到新表 CREATE TABLE 新表 SELECT * FROM 旧表 3.复制旧表的数据到新表(假设两个表结构一样) ...
CREATE TABLE 新表 SELECT * FROM 旧表 2.只复制表结构到新表 代码如下: CREATE TABLE 新表 SELECT * FROM 旧表 WHERE 1=2 即:让WHERE条件不成立. 方法二:(低版本的mysql不支持,mysql4.0.25 不支持,mysql5已经...
B:create table tab_new as select col1,col2… from tab_old definition only 5、说明:删除新表 drop table tabname 6、说明:增加一个列 Alter table tabname add column col type 注:列增加后将不能删除。DB2...
B:create table tab_new as select col1,col2… from tab_old definition only 5、说明:删除新表drop table tabname 6、说明:增加一个列 Alter table tabname add column col type 注:列增加后将不能删除。...
select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b 6、说明:外连接查询(表名1:a 表名2:b) select a.a, a.b, a.c, b.c, b.d, b.f from a ...
B:create table tab_new as select col1,col2… from tab_old definition only 5、说明:删除新表 drop table tabname 6、 增加一个列:Alter table tabname add columnname col type 删除一个列:Alter table ...
select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b 6、说明:外连接查询(表名1:a 表名2:b) select a.a, a.b, a.c, b.c, b.d, b.f from a...
select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b 6、说明:外连接查询(表名1:a 表名2:b) select a.a, a.b, a.c, b.c, b.d, b.f from a ...
B:create table tab_new as select col1,col2… from tab_old definition only 5、说明:删除新表 drop table tabname 6、说明:增加一个列 Alter table tabname add column col type 注:列增加后将不能删除。DB2...
select * from student where name like '%[a][o]%'; select * from student where name not like '%a%'; select * from student where name like 'ja%'; select * from student where name not like '%[j,n]%'; ...
create snapshot snapshot_to_study as select * from TABLE_NAME@to_study; 创建角色 create role aa identified by aaa; 授权 grant create snapshot,alter snapshot to aaa; grant aaa to emp; create ...
--if exists(select * from sysobjects where name='视图名') -- drop view 视图名 --go --create view 视图名 --as --select 字段名 from 表名 [条件] --go --主外健约束语句没有执行 use T90ERP go --********...
'',A表) select * from 数据库名..B表 /*************导入Access********************/ insert into B表 selet * from openrowset('Microsoft.Jet.OLEDB.4.0', 'x:\A.mdb';'admin';'',A表) 文件名为参数 declare ...
create table table_name_new as (select * from table_name_old); 只复制表结构 create table table_name_new as select * from table_name_old where 1=2; 或者 create table table_name_new like table_name...