再次认识mysql(三)

查看表结构 desc table t1

建表过程  就是创建表头的过程 (声明列的过程)

create table t1(id int(10) unsigned primary key auto_increment ,name varchar(20))

mysql常见数据类型:整型 十进制 十六进制 八进制 浮点数 字符串 null

整型 主要有  tinyint 1个字节  smallint 2个字节  mediumint 3个字节 int 4个字节   bigint 8个字节

整型可选参数 unsigned  无符号 列的值从0开始  不为负   

                         zerofill   0填充至固定宽度 非负  常用于学号 编号    zerofill 4                        


浮点数主要有 单精度float  双精度 double

float(M,D)  double(M,D)   M是精度 总位数    D标度 小数点后面的位数   有精度损失

定点型  decimal(m,d)常用于保存货币,m表示数字的最大数(总共位数),d表示小数点右侧数字的数目

字符型

char(M) 定长类型  0<=M<=255     实际所占空间 M  空格字符会被丢失

varchar(M) 变长类型   0<=M<=65535  实际所占空间 存储字符+位置字符  长字节数据 使用变长类型 较为合理   

枚举型  性别

create table t1(gender enum('男',‘女’));

日期类型 Date  Time datetime

时间戳一般用int usigned存储

create table t1 (id int not null default 0,name char(10) not null default '');

主键 primary key  此列不重复 区分每一行  主键可以设置自增  auto_increment

建表常用原则  定长与变长分离    常用列与不常用列分离


列的删除增加修改

alter table t1 drop username;

alter table test add pid int not null default 0 first;

alter table t1 add name  tinyint unsigned not null default 0  after weight ;

alter table t1 change height  shengao smallint;

alter table test modify gender char(4)  not null default ''; 不能修改名称

alter table test change oldname newname  int   unsigned not null  default 0;





 


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值