mysql 添加外鍵約束
添加外鍵
alter table table_name add foreign key fk_product_id (product_id) references product(id)
??table_name 為表名, fk_product_id 為外鍵名,第一個括號里填寫外鍵列名, product為表名,第二個括號里是寫外鍵在product表中關聯的列名。
刪除外鍵
alter table table_name drop foreign key fk_product_id
查看外鍵
show create table table_name
結束語
??工作中幾乎不需要用到外鍵約束,創建相關索引即可。
讀后有收獲,小禮物走一走,請作者喝咖啡。
Buy me a coffee. ?Get red packets.作者:樓蘭胡楊
本文版權歸作者和博客園共有,歡迎轉載,但請注明原文鏈接,并保留此段聲明,否則保留追究法律責任的權利。

浙公網安備 33010602011771號