[英]Adding or alter foreign key to a table in mysql
I am new beginner on sql query on mysql.我是 mysql 上 sql 查询的新手。 I have table structure like this :
我有这样的表结构:
--------------------------------- ----------------------------
| 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 |----- ----------------------------
---------------------------------
I got a problem like this.我遇到了这样的问题。
You can create foreign key and cascading for child auto delete as per below-您可以为子自动删除创建外键和级联,如下所示 -
ALTER TABLE table_office
ADD CONSTRAINT FK_table_office_id_complaint FOREIGN KEY (id_complaint)
REFERENCES table_detail_complaint (id_complaint)
ON DELETE CASCADE;
For other part of your question share more details what kind of information you want to store and how you will use them..对于您问题的其他部分,请分享更多详细信息,您要存储什么样的信息以及您将如何使用它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.