mysql建立外來鍵語句

weixin_30488085發表於2020-04-06
alter table t_book add constraint `fk` foreign key (`bookTypeId`) references t_booktype(`id`);
或者在創表時直接加上

CREATE TABLE t_book(
id int primary key auto_increment,
bookName varchar(20),
author varchar(10),
price decimal(6,2),
bookTypeId int,
constraint `fk` foreign key (`bookTypeId`) references `t_bookType`(`id`)
);

轉載於:https://www.cnblogs.com/bupt-liqi/p/11151126.html

相關文章