# 创建整形表
# create table my_int(
# int_1 tinyint,
# int_2 smallint,
# int_3 int,
# int_4 bigint
# )charset utf8;
# 插入数据
# insert into my_int
# values(100,100,100,100);
# 有效数据
# insert into my_int
# values(`a`,`b`,`199`,`f`);
# 无效数据:类型限定
# insert into my_int
# values(255,10000,100000,1000000);
# 错误:超出范围
# 给表增加一个无符号类型
# alter table my_int add int_5
# tinyint unsigned;无符号类型
# 插入数据
# insert into my_int
# values(127,10000,100000,1000000,255);
# 指定显示宽度为1
# alter table my_int add int_6
# tinyint(1)unsigend;
# 插入数据
# insert into my_int
# values(127,0,0,0,255,255);
# 显示宽度为2,0填充
# alter table my_int add int_7
# tinyint(2) zerofill;
# 插入数据
# insert into my_int
# values(1,1,1,1,1,1,1);
# insert into my_int
# values(100,100,100,100,100,100,100);
# 浮点数表
# create table my_float(
# f1 float,
# f2 float(10,2), 10位在精度范围之内
# f3 float(6,2) 6位在精度范围之内
# );
# 插入数据
# insert into my_float
# values(1000.10,1000.10,1000.10);
# insert into my_float
# values(1234567890,12345678.90,1234.56);
# insert into my_float
# values(3e38,12345678.90,1234.56);
# insert into my_float
# values(9999999999,99999999.99,9999.99); 后两个是最大值
# 超出长度插入数据
# insert into my_float
# values(123456,1234.12345678,123.9876543); 小数部分可以超出长度
# insert into my_float
# values(123456,1234.12,12345.56); 最后一个整数部分超出
# 创建定点数表
# create table my_decimal(
# f1 float(10,2),
# d1 decimal(10,2)
# );
# 插入数据
# insert into my_decimal
# valuse(12345678.90,12345678.90);
# 有效数据
# insert into my_decimal
# values(1234.123456,1234.123456);
# 小数部分可以超出
# 查看警告
# show warnings;
# 插入数据
# insert into my_decimal
# values(99999999.99,99999999.99);
# 没有问题
# insert into my_decimal
# values(99999999.99,99999999.999);
# 进位超出范围
# 创建时间日期表
# create table my_date(
# d1 datetime,
# d2 date,
# d3 time,
# d4 timestamp,
# d5 year
# );
# 插入数据
# insert into my_date
# values('2019-11-21 13:38:36','2019-11-21','-213:38:36','2019-11-21 13:38:36',2015);
# 时间使用负数
# insert into my_date
# values('2019-11-21 13:38:36','2019-11-21','-213:38:36','2019-11-21 13:38:36',2015);
# insert into my_date
# values('2019-11-21 13:38:36','2019-11-21','-213:38:36','2019-11-21 13:38:36',2015);
# insert into my_date
# values('2019-11-21 13:38:36','2019-11-21','-213:38:36','2019-11-21 13:38:36',2015);
# 2表示过去2天,就是48小时 year可以使用可以使用2位或者4位
# insert into my_date
# values('2019-11-21 13:38:36','2019-11-21','-213:38:36','2019-11-21 13:38:36',69);
# insert into my_date
# values('2019-11-21 13:38:36','2019-11-21','-213:38:36','2019-11-21 13:38:36',70);
# timestamp:修改记录
# update my_date set d1='2019-11-21 13:46:45' where d5=2069;
# 创建枚举表
# create table my_enum(
# gender enum('男','女','保密')
# );
# 插入数据
# insert into my_enum
# values('男'),('保密'); 有效数据
# insert into my_enum
# values('male'); 错误数据:没有该元素
# 将字段结果取出来进行+0运算
# select gender + 0, gender
# from my_enum;
# 数值插入枚举元素
# inser into my_enum
# values(1),(2);
# 创建班级列表
# create table my_class(
# name varchar(20) not null,
# room varchar(20) null 代表允许为空,不写默认就是允许为空
# );
# 创建表
# create table my_teacher(
# name varchar(20) not null comment'姓名',
# money decimal(10,2) not null comment'工资'
# );
# 默认值
# create table my_default(
# name varchar(20) not null,
# age tinyint unsigend default 0,
# gender enum('男','女','保密')
# default'男'
# );
# 插入数据
# insert into my_default (name)
# values('阿飞');
# insert into my_default
# values('男闺蜜',18,default);
# 添加主键
# create table my_pril(
# name varchar(20) not null comment'姓名',
# number char (10) primary key comment'学号:bc2019+0001, 不能重复'
# );
# 复合主键
# create table my_pri2(
# number char(10) comment
# '学号:bc20190001',
# course char(10) comment
# '课程代码:bc25890001',
# score tinyint unsigned default 60 comment'成绩',
#增加主键限制:学号和课程号应该是对应的,具有唯一性
# primary key(number,course)
# );
# 追加主键
# create table my_pri3(
# course char(10) not null comment '课程代码:bc254414585',
# name varchar(10) not null comment '课程名字'
# );
# alter table 表名 add primary key(字段列表);
# 第一种方式
# alter table my_pri3 modify course
# char(10) primary key comment
# '课程代码:bc25890001';
# 第二种方式
# alter tbale my_pri3 add primary
# key(course);