在表中定义列是,应该指定列的名称、数据类型,若有默认值应指定默认值。

下面创建一个表名:"customers"的表作为例子:

create table `customers`(

`id` int unsigned AUTO_INCREMENT primary key,

`first_name` varchar(20),

`last_name` varchar(20),

`country` varchar(20));

执行成功以后就在数据库创建了一个名为"customers"的表。

接下来,使用:desc customers;查看表如图所示:

Mysql数据库——创建表与表的克隆

接下来,我们再创建一张表“payments”

create table `payments`(

`customer_name` varchar(20) primary key,

`payment` float);

同样查看表"desc payments":

Mysql数据库——创建表与表的克隆

克隆表结构:我们可以将一个表的结构克隆到新表中。

create table new_customers like customers;

然后我们查看该数据库中的表:"show tables" 

Mysql数据库——创建表与表的克隆

 

关注公众号:"一起玩转Python"获取更多资源

Mysql数据库——创建表与表的克隆

相关文章: