课程回顾
- 数据库相关SQL
- 查询所有 show databases;
- 创建 create database db1 character set utf8/gbk;
- 查询详情 show create database db1;
- 删除数据库 drop database db1;
- 使用数据库 use db1;
- 表相关SQL
- 创建表 create table t1(name varchar(10),age int)charset=utf8;
- 查询所有 show tables;
- 查询详情 show create table t1;
- 表字段 desc t1;
- 删除表 drop table t1;
- 修改表名 rename table t1 to t2;
- 添加字段 alter table t1 add 字段名 类型 first/after xxx;
- 删除字段 alter table t1 drop 字段名;
- 修改字段 alter table t1 change 原名 新名 新类型;
- 数据相关SQL
- 插入数据 insert into t1(name,age) values(xxx,xxx),(xxx,xxx);中文问题 如果存在中文问题 执行 set names gbk;
- 查询数据 select 字段信息 from t1 where 条件;
- 修改数据 update t1 set xxx=xxx where 条件;
- 删除数据 delete from t1 where 条件;
- 数据类型
- 整数 int(m) 和 bigint(m) m代表显示长度 需要结合zerofill关键字使用
- 浮点数 double(m,d) m代表总长度 d代表小数长度 超高精度浮点数decimal
- 字符串: char:不可变长度 执行效率高 255 varchar 可变长度 节省空间,建