文章目录
1. 表的操作
1.1 创建表
CREATE TABLE table_name (
field1 datatype,
field2 datatype,
field3 datatype
) character set 字符集 collate 校验规则 engine 存储引擎;
- field 表示列名
- datatype 表示列的类型
- character set 字符集
- collate 校验规则
- engine 存储引擎
但是不同的存储引擎,创建表之后产生的文件不一样。
1.2 查看有多少张表
show tables;
1.3 查看表结构
desc 表名;
1.4 插入数据、查询数据
插入全部列 | insert into 表名 values(值1,值2……) |
---|---|
插入部分列 | insert into 表名(列名1,列名2……) values(值1,值2……) |
查询全部列 | select * from 表名 |
查询部分列 | select 列1,列2……from 表名 |
1.5 修改表
1.5.1 向表中添加字段
alter table 表名 add 新字段 新字段类型[注 释] [插入字段的位置];
1.5.2 修改字段的类型
alter table 表名 modify 字段 字段类型;
1.5.3 删除字段
alter table 表名 drop 字段名称;
1.5.4 修改表名称
alter table 表名 rename [to] 新名称;
1.5.5 修改字段名称
alter table 表名 change 字段名 新字段名 新字段类型;
1.6 删除表
drop table [if exists] 表名;