表-创建、查看
1. 创建表
创建表时,需要指定表名、字段名、字段的数据类型等信息。如
create table if not exists `demo`.`first_table`(
id int unsigned auto_increment primary key,
first_name varchar(20),
last_name varchar(20),
country varchar(20)
) engine=InnoDB;
常用的数据类型如下:
- 数字:tinyint , smallint , mediumint , int , bigint , bit;
- 浮点数:decimal , float , double;
- 字符串:char , varchar , binary , varbinary , blob , text , enum , set;
- Spatial 类型;
- Json数据类型(mysql8.0新增);
2. 列出所有表
show tables;
3. 查看表结构
desc 表名
desc first_table;
4. 查看建表语句
show create table 表名
show create table first_table;
5. 克隆表结构
create table 新表名 like 就表名
create table second_table like first_table;
验证一下
还没有评论,来说两句吧...