MySQL数值类型与建表过程

一、数值类型

  • 整型

Tinyint:占据空间:1字节;存储范围:-128-127,0-255(相当与bool)
Smallint:占据空间:2字节;
Mediumint:占据空间:3字节;
Int:占据空间:4字节;
bigint:占据空间:8字节;

  • 浮点型/定点型

1个字节 8个位
0-2^8-1 ,0-255

float(M,D)
M叫“精度”(总位数,不包含点)
D叫“标度”(小位数)

  • 字符串型

char(M)
varchar(M)
text 文本类型

  • 日期时间类型

Date 日期
Time 时间
Datetime 日期时间类型
year 年类型

二、建表

所谓建表就是一个声明列的过程

creat table 表名 (
列名1声明 列类型 列1参数,
列名2声明 列类型 列2参数,
......
......
列名n声明 列类型 列n参数
)engine myisam/innodb/bdb charset utf8/gbk/latinl...

示例:
create table member (
id int unsigned auto_increment primary key,
username char(20) not null default '',
gender char (1) not null default '',
weight tinyint unsigned not null default 0,
birth date not null default '0000-00-00',
salary decimal(8,2) not null default 0.00,
lastlogin int unsigned not null default 0
)engine myisam charset utf8;

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务