mysql学习笔记(二)

您所在的位置:网站首页 column是什么意思呀 mysql学习笔记(二)

mysql学习笔记(二)

2024-07-11 20:09| 来源: 网络整理| 查看: 265

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);


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3