![](/img/trans.png)
[英]MySQL Error Code 1215: Cannot add foreign key Constraint on ALTER TABLE : Mysql
[英]Adding or alter foreign key to a table in mysql
我是 mysql 上 sql 查詢的新手。 我有這樣的表結構:
--------------------------------- ----------------------------
| Table office | | Table_detail_complaint |
--------------------------------- ----------------------------
|(PK) id_office | ----|(PK) id_complaint |
| name | | | complaint_2 |
| complaint_1 | | | time_response_2 |
| time_response_complaint1 | | | complaint_3 |
| address | | | time_response_3 |
|(FK) id_complaint |----- ----------------------------
---------------------------------
我遇到了這樣的問題。
您可以為子自動刪除創建外鍵和級聯,如下所示 -
ALTER TABLE table_office
ADD CONSTRAINT FK_table_office_id_complaint FOREIGN KEY (id_complaint)
REFERENCES table_detail_complaint (id_complaint)
ON DELETE CASCADE;
對於您問題的其他部分,請分享更多詳細信息,您要存儲什么樣的信息以及您將如何使用它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.