day31 表单的一对多和多对多,增删改
补充:
auto_increment 自动增加(Int)数据
只有mysql 里面可以
unsigned无符号
多对一关系可以在多的一方添加一个列来维系
比如可以在学生表里加学院表
多对多可以拆成两个一对多。需要中间表
– 创建选课表
create table tb_record
(
rec_id bigint unsigned not null auto_increment comment ‘流水号’,
student_id int not null comment’学号’,
class_id int unsigned not null comment’课号’,
score decimal(4,1) not null default 0 comment’分数’,
is_examed boolean not null default 0 comment ‘是否考试’,
sel_date datetime not null comment’选课日期’,
constraint uk_record_student_id_class_id unique(student_id,class_id),
primary key(rec_id)
);
加外键约束:
alter table tb_student add constraint fk_student_col_id
foreign key(collage_id) references tb_collage(collage_id);
1,对应的类型要一致
2,有数据会报