• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

MySQL中两种快速创建空表的方式的区别

发布: 2008-6-10 17:03 | 作者: Chad | 来源: 赛迪网 | 查看: 31次 | 进入软件测试论坛讨论

领测软件测试网

MySQL中两种快速创建空表的方式的区别

作者:Chad 来源:赛迪网

  在MySQL中有两种方法

  1、create table t_name select ...
  2、create table t_name like ...

  第一种会取消掉原来表的有些定义,且引擎是系统默认引擎。

  手册上是这么讲的:Some conversion of data types might occur. For example, the AUTO_INCREMENT attribute is not preserved, and VARCHAR columns can become CHAR columns.

  第二种就完全复制原表。

  先建立测试表:

  mysql> create database dbtest;
  Query OK, 1 row affected (0.03 sec)
  mysql> use dbtest;
  Database changed
  mysql> create table t_old
  -> (
  -> id serial,
  -> content varchar(8000) not null,
  -> `desc` varchar(100) not null)
  -> engine innodb;
  Query OK, 0 rows affected (0.04 sec)
  mysql> show create table t_old;
  +-------+-------------------------------------------------+
  | Table | Create Table |
  +-------+------------------------------------------------+
  | t_old | CREATE TABLE `t_old` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `content` varchar(8000) NOT NULL,
  `desc` varchar(100) NOT NULL,
  UNIQUE KEY `id` (`id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
  +-------+----------------------------------------------------+
  1 row in set (0.00 sec)

  第一种方式:

  mysql> create table t_select select * from t_old where 1 = 0;
  Query OK, 0 rows affected (0.04 sec)
  Records: 0 Duplicates: 0 Warnings: 0
  mysql> show create table t_select;
  +----------+--------------------------------------------+
  | Table | Create Table +----------+---------------------------------------------+
  | t_select | CREATE TABLE `t_select` (
  `id` bigint(20) unsigned NOT NULL default '0',
  `content` varchar(8000) NOT NULL,
  `desc` varchar(100) NOT NULL
  ) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
  +----------+-------------------------------------------+
  1 row in set (0.00 sec)

  第二种方式:

  mysql> create table t_like like t_old;
  Query OK, 0 rows affected (0.02 sec)
  mysql> show create table t_like;
  +--------+-------------------------------------------------+
  | Table | Create Table |
  +--------+-------------------------------------------------+
  | t_like | CREATE TABLE `t_like` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `content` varchar(8000) NOT NULL,
  `desc` varchar(100) NOT NULL,
  UNIQUE KEY `id` (`id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
  +--------+-------------------------------------------------+
  1 row in set (0.00 sec)
  mysql>

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/

TAG: Mysql MySQL mysql mySQL


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网