oracle复制表结构mysql_mysql表结构复制

作者: 弦乐之花 | 可以转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明

我们特别是oracle dbas常常会通过ctas来复制表结构,这样复制出来的表实际上会丢掉表的一些属性,索引就更不说了,在mysql中这样来复制表其实得到的也只是表大体结构而已。

还好mysql提供了create table like命令方便进行表结构的复制,废话不说了

root@mysql 02:55:17>use test

Database changed

root@test 03:25:22>create table t1(a int,b int,key (a)) engine=myisam;

Query OK, 0 rows affected (0.00 sec)

root@test 03:25:49>show create table t1G

*************************** 1. row ***************************

Table: t1

Create Table: CREATE TABLE `t1` (

`a` int(11) DEFAULT NULL,

`b` int(11) DEFAULT NULL,

KEY `a` (`a`)

) ENGINE=MyISAM DEFAULT CHARSET=gbk

1 row in set (0.00 sec)

root@test 03:25:55>create table t2 as select * from t1 where 1=0;

Query OK, 0 rows affected (0.00 sec)

Records: 0 Duplicates: 0 Warnings: 0

root@test 03:26:16>show create table t2G

*************************** 1. row ***************************

Table: t2

Create Table: CREATE TABLE `t2` (

`a` int(11) DEFAULT NULL,

`b` int(11) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=gbk

1 row in set (0.00 sec)

root@test 03:26:25>create table t3 like t1;

Query OK, 0 rows affected (0.00 sec)

root@test 03:26:44>show create table t3G

*************************** 1. row ***************************

Table: t3

Create Table: CREATE TABLE `t3` (

`a` int(11) DEFAULT NULL,

`b` int(11) DEFAULT NULL,

KEY `a` (`a`)

) ENGINE=MyISAM DEFAULT CHARSET=gbk

1 row in set (0.00 sec)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值