`
nicegege
  • 浏览: 589424 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

mysql数据库创建表

 
阅读更多

1.创建一个名称为employee的mysql默认类型MyISAM表

create table employee (id smallint(5) not null,depno int(5) not null,name varchar(20) not null,cardnumber int(15) not null,primary key (id,depno));

插入一条记录

insert into employee values(1,805,'jim',2010090101);

2.创建和employee的表结构一样的一个表employee1

create table employee1 like employee

3.创建带有employee表数据的表employee2

create table employee2 select * from employee

4.在mysql数据库中建立一个employee表

create table mysql.employee like employee;

5.显示创建表employee的表结构
mysql> desc mysql.employee;
+------------+-------------+------+-----+---------+-------+
| Field      | Type        | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| id         | smallint(5) | NO   | PRI | NULL    |       |
| depno      | int(5)      | NO   | PRI | NULL    |       |
| name       | varchar(20) | NO   |     | NULL    |       |
| cardnumber | int(15)     | NO   |     | NULL    |       |
+------------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

mysql> drop table mysql.employee;
Query OK, 0 rows affected (0.00 sec)

6.在mysql数据库中创建一个带有数据的employee表
mysql> create table mysql.employee select  * from employee;
Query OK, 1 row affected (0.02 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> select * from mysql.employee;
+----+-------+--------+------------+
| id | depno | name   | cardnumber |
+----+-------+--------+------------+
|  1 |   805 | liming | 2010090101 |
+----+-------+--------+------------+
1 row in set (0.00 sec)

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics