数据库数据类型表操作

1、数据类型

1.1 numeric数字类型

	整数: tinyint smallint mediumint int bigint
	小数: float double decimal(p,s) numeric(p,s)

在这里插入图片描述

	DOUBLE PRECISION[(M,D)] [UNSIGNED] [ZEROFILL],REAL[(M,D)] [UNSIGNED] [ZEROFILL]
-- 建立表(字段列使用数据类型)
create table student(
	id int unsigned auto_increment,
	name varchar(30),
	/* age bigint , 不能这样写,bigint 是占用8字节 */
	age tinyint, /* 整数只能存储整数 18 */
	money decimal(10,2), /* 99999999.99 最大数字 如果没有数字则是 0.00 */
	primary key(id)
)

-- 插入数据
insert into student values(null,'jack',18,200);

-- 查询数据
select * from student;

	无符号 [UNSIGNED]    填充0 [ZEROFILL]
-- unsigned 演示
-- age int
-- age int unsigned 无符号,没有负数,从0开始 速度快
-- zerofill 0填充
-- age int(3) zerofill 如果插入数字1 则查询时为001
-- 3代表数字3位宽度,不是3位数,如果不够三位,则前边补0

create table t1(
	name varchar(30),
	n1 int,
	n2 int unsigned,
	n3 int(3), /* 此时3没有意思没有任何作用 */
	n4 int(5) zerofill /* 如果内容不够5位,则补0 */
)

insert into t1 values('jack',1,2,3,4);
select * from t1;  -- jack 1 2 3 00004

insert into t1 values('lisi',-1,0,-3,2342342);


use db;
show tables;
-- 数据类型 数字
-- 整形数字 tinyint smallint mediumint int bigint
-- 小数数字 float doule decimal(p,s) numric(p,s)

-- 建立表
create table t2(
	c1 tinyint,
	c2 smallint,
	c3 bigint,
	f1 float,
	f2 float(6,2),
	d1 double(2,1),
	d2 double(6,2),
	d3 double(7,3)
)

show create table t1;
select * from t2;
insert t2 value(1,2.5,3,4,1,2,3,4,5);


create table t3(
	c1 tinyint, /* -128~127 */
	c2 tinyint unsigned, /* 0-255 */
	c3 int(5) unsigned zerofill,
	c4 tinyint unsigned default 18,
	d1 decimal(15,3) unsigned, /* decimal(3,0) unsigned 0.0~99.9 */
	d2 decimal(15,3) unsigned zerofill
)

insert t3(c1,c2,c3,d1,d2) value(1,1,1,1,1);
select * from t3;

create table t4(
	d1 decimal(3,0) unsigned zerofill,
	d2 decimal(3,1) /* -99.9 ~ 99.9 */
)

insert into t4 value(1,-2),(18,99),(1.5,6.6);
insinsert into t4 value(999,99.111);

select * from t4;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值