1、default ;设置默认参数,且不能更改。
2、not null ;传参数时不能为空。
3、unique ;在该列不能value 不能重复。
4、primary key ;设置主键,不能含有重复的value。
5、foreign key ……reference….. ; 保证主键和外键数据的一致性。
mysql> create table teacher
-> (
-> teacher_wife char(10),
-> teacher_id int primary key,
-> teatchr_age int not null,
-> teacher_name char(20),
-> teacher_money int default ‘3000’
-> teacher_geade int,
-> unique(teacher_wife)
-> );
mysql> create table student
->(
-> student_id int primary key,
-> student_age int not null,
-> foreign key(student_id) references teacher(teacher_id)
->);
一、默认参数
teacher_money int default ‘3000’
二、插入不能为空
insert into teacher(teacher_wife,teacher_age) values
(“whose” ) 这个则会报错,teacher_age必须传参
teatchr_age int not null,
三、不能含有重复的值
unique(teacher_wife)
四、保证主键的独一性
第3个复合主键则是当传的两个参都相同时候才会报错。
teacher_id int primary key,
primary key teacher_id,
primary key( teacher_id,teacher_age)
五、保证数据的一致性
最不好理解的一个。外键,为了保证数据的一致性。
在插入数据时候,必须得保证在主键里面有了对应的值,才行,删除也是,必须先删除主键。
foreign key(student_id) references teacher(teacher_id)
浙公网安备 33010602011771号