版权声明:酷酷的锐 https://blog.csdn.net/weixin_42057767/article/details/82430486
1:数值类型
tinyint,smallint,mediumint,int/integer,bigint, float,double,decimal
tinyint : 1字节大小,范围-128~127
tinyint类型:
create table temp_03 (tid tinyint);
insert into temp_03 values(-128);
insert into temp_03 values(127);
128超出范围报错
insert into temp_03 values(128);
smallint: 2字节大小,范围-32768~32767。
smallint类型:
create table temp_04(tid smallint);
insert into temp_04 values(-32768);
insert into temp_04 values(32767);
超范围会报错
insert into temp_04 values(32768);
int/integer:常用数值类型,占 4字节
int/integer类型:
create table temp_05 (tid int(1));
insert into temp_05 values(-2147483648);
insert into temp_05 values(2147483647);
不可以超过范围
insert into temp_05 values(2147483648);
大整数类型, 范围与java语言的long的范围类似。
float与double
float:单精度类型,占4字节。
float类型:
不规定长度时,默认进行四舍五入,保留0或1位小数
create table salary_t (salary float);
insert into salary_t values(10000.123456);
insert into salary_t values(10000.56789);
insert into salary_t values(10000);
select * from salary_t;
规定长度时:float(m,n):m表示数据的有效位数,n表示小数点后保留的位数。整数位:最大值为m-n;
create table salary_t01 (salary float(6,2));
insert into salary_t01 values(10.5678);
insert into salary_t01 values(10000.5678);
insert into salary_t01 values(9999.5678);
insert into salary_t01 values(0.5678);
select * from salary_t01;
float(m,0)与float(m),指的是整数位的最大位数。
create table salary_t02 (salary float(6,0));
insert into salary_t02 values(9999.5678);
insert into salary_t02 values(999999);
select * from salary_t02;
double:双精度类型,占8字节
规定长度写法: double(m,n):有效位数是m,小数点后保留n位。整数位:m-n
create table salary_t03 (salary double(4,2));
insert into salary_t03 values(100);
insert into salary_t03 values(99.5678);
select * from salary_t03;
PS:decimal:与float和double的用法一样,decimal(m,n)