数据库,表参考【mysql】简单删除语句
为图书表同时添加主键和自增
alter table book
change id id int unsigned
auto_increment primary key;
为图书表添加唯一约束
alter table book add unique(id);
为图书表添加联合主键
alter table book add primary key(id,name);
删除图书表唯一约束
alter table book drop index id;
为图书表(book)添加外键约束,关联学生表(student),关联的字段是id
alter table book
add constraint fk_book_id
foreign key(id) references student(id);
为图书表·(book)添加外键约束,关联学生表(student),设置级联删除:on delete cascade
alter table book
add constraint fk_book_id
foreign key(id) references student(id) on delete cascade ;
为图书表(book)添加外键约束,关联学生表(student),设置级联更新:on update cascade
alter table book
add constraint fk_book_id
foreign key(id) references student(id) on update cascade ;
为图书表添加一条数据
insert into book set id=5, name='盗墓笔记', author='南派三叔', Price=39.8,Press='华银社';