MySQL 入门笔记(二)
MySQL 常用数据类型
类型 | 大小 | 范围 | 用途 |
---|---|---|---|
INTEGER | 4 bytes | (-2 147 483 648,2 147 483 647) | 大整数值 |
FLOAT | 4 bytes | (-3.402 823 466 E+38,-1.175 494 351 E-38),0,(1.175 494 351 E-38,3.402 823 466 351 E+38) | 单精度浮点数值 |
DOUBLE | 8 bytes | (-1.797 693 134 862 315 7 E+308,-2.225 073 858 507 201 4 E-308),0,(2.225 073 858 507 201 4 E-308,1.797 693 134 862 315 7 E+308) | 双精度浮点数值 |
DATE | 3 | 1000-01-01/9999-12-31 | 日期值 |
DATETIME | 8 | 1000-01-01 00:00:00/9999-12-31 23:59:59 | 混合日期和时间值 |
TIMESTAMP | 4 | 1970-01-01 00:00:00/2038结束时间是第 2147483647 秒,北京时间 2038-1-19 11:14:07,格林尼治时间 2038年1月19日 凌晨 03:14:07 | 混合日期和时间值,时间戳 |
VARCHAR | 0-65535 bytes | 变长字符串 |
查询表
- 查询某个数据库下所有表名称
show tables;
- 查询某个某个表的创建语句 以及字符集
show create table xxx;
- 查询表结构
desc xxx;
创建
- 创建表
create table if not exists tb1 (
id int,
name varchar(32),
age int,
score double(4,1),
birthday date,
insert_time timestamp
);
- 复制表
create table xxx2 like xxx1;
删除
drop table xxx;
drop table if exists xxx;
修改
- 修改表名称
alter table xxx1 rename to xxx2;
- 修改表字符集
alter table xxx character set utf8;
- 添加列
alter table xxx add xxx varchar(10)
- 修改列名称 类型
alter table xxx change xxx1 xxx2;
- 删除列
alter table xxx drop xxx;