mysql创建外键语句

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

你可能感兴趣的:(mysql创建外键语句)