创建表时添加外键约束:
[CONSTRAINT<外键约束名>] FOREIGN KEY(列名) references <主表名> (主键)
修改表时添加外键约束:
ALTER TABLE bookinfo ADD FOREIGN KEY(book_category_id) REFERENCES bookcategory(category_id);
备注: bookinfo(子表名) bookcategory(主表名)
alter table bookinfo add foreign key (book_category_id) references bookcategory(category_id);
删除外键约束:
ALTER TABLE bookinfo DROP FOREIGN KEY fk_cid;
alter table bookinfo drop foreign key fk_cid;
备注:bookinfo(子表名)