Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4729441
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类: Mysql/postgreSQL

2010-05-07 18:58:02

复制表内的数据用:
create table bak select * from table;

复制表的结构:
create table bak like table;
这个可以用于快速创建空表,这个空表的结构与原来的表也是一样的!

mysql> create table test(id INT auto_increment primary key, name VARCHAR(20))engine=Innodb;
Query OK, 0 rows affected (0.37 sec)

mysql> show create table test;
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                               |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
| test  | CREATE TABLE `test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.04 sec)

mysql> desc test;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(11)     | NO   | PRI | NULL    | auto_increment |
| name  | varchar(20) | YES  |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.13 sec)

mysql>
mysql> insert into test(name) values('kenthyzhang');
Query OK, 1 row affected (0.08 sec)

mysql> select * from test;
+----+-------------+
| id | name        |
+----+-------------+
|  1 | kenthyzhang |
+----+-------------+
1 row in set (0.00 sec)

mysql> insert into test(name) values('jeremy');
Query OK, 1 row affected (0.03 sec)

mysql> select * from test;
+----+-------------+
| id | name        |
+----+-------------+
|  1 | kenthyzhang |
|  2 | jeremy      |
+----+-------------+
2 rows in set (0.00 sec)

mysql> create table test1 select * from test;
Query OK, 2 rows affected (0.02 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> create table test2 like test;
Query OK, 0 rows affected (0.04 sec)

mysql> show create table test1;
+-------+------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                       |
+-------+------------------------------------------------------------------------------------------------------------------------------------+
| test1 | CREATE TABLE `test1` (
  `id` int(11) NOT NULL DEFAULT '0',
  `name` varchar(20) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+-------+------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> show create table test2;
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+
| test2 | CREATE TABLE `test2` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> show create table test;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| test  | CREATE TABLE `test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select * from test;
+----+-------------+
| id | name        |
+----+-------------+
|  1 | kenthyzhang |
|  2 | jeremy      |
+----+-------------+
2 rows in set (0.00 sec)

mysql> select * from test1;
+----+-------------+
| id | name        |
+----+-------------+
|  1 | kenthyzhang |
|  2 | jeremy      |
+----+-------------+
2 rows in set (0.00 sec)

mysql> select * from test2;
Empty set (0.00 sec)

mysql>

阅读(958) | 评论(3) | 转发(0) |

chinaunix网友2010-05-31 22:31:46

MBT is based on Africa's indigenous people to create innovative walking barefoot, and wear this shoe can stimulate the body to relax the muscles so that the muscles of heat to be released, consumed calories, thus to achieve weight loss results. MBT's pursuit of beauty in order to satisfy customers, design a variety of styles, such as Mbt Chapa shoe, MBT Lami Shoe