mysql学习笔记(二)

MySQL表中的一些名词

1.字段(column):column顾名思义就是列的含义,所以字段是指table表中列的名称。

2.字段类型:字段类型大体分为三部分:时期类型,数值类型,字符串类型。

数值类型:

 

字符串类型:

char和varchar的区别:

1.char(n) 若存入字符数小于n,则以空格补于其后,查询之时再将空格去掉。

举个例子:定义一个char[10]和varchar[10],如果存进去的是‘abcd’,那么char所占的长度依然为10,除了字符‘abcd’外,后面跟六个空格,而varchar就立马把长度变为4了,取数据的时候,char类型的要用trim()去掉多余的空格,而varchar是不需要的。

2.char类型的字符串检索速度要比varchar类型的快。
 

时间类型:

3.约束(字段修饰符)

1. unsigned:无符号位,一般用于数值int类型。

alter table student  motify  id(5)   not null   unsigned  auto_increment;

2. not null (非空约束):

alter table student  motify  id(5)   not null   unsigned  auto_increment;

    修改非空约束:修改非空就是改为空null

alter table student  motify  id(5)  null unsigned  auto_increment;

3. auto_increment (自动增长): 一般用于id号设置

alter table student motify id(5) unsigned  not null  auto_increment  ;

4.primary key  (添加主键约束):一个表只有一个主键,设置主键的列查询会非常快,所以一般会用聚集索引。

alter table student add primary key (id);

5.foreign key (添加外键约束): 何为外键,当建表时需要用到另外一个表的主键作为本表的的主键时,需要设置外键。设置外间后,若想在删除本表数据时会级联删除或者默认删除其他方式。

 alter table student add foreign key id reference otherstudent(id);

6.default(默认值约束):

alter table student add id int not null default;

7.unique(唯一约束):本列不允许出现重复的值,但是可以为多个null。

alter table student add unique(id);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值