How to make a connection in MySQL?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
6 views
Hello!
The Internet to read the article and watched the video tutorials but I did not get to create a relationship between tables
so let's say there are two table
1 - post (id, status, date)
2 - post_content (id, parent_id, language, name, content)

when you remove the post you need to remove all the contents are in different languages
how can I do this?
I have a version of MySQL 5.7
in phpMyAdmin how to do? or need request
in my opinion, I do not really understand to associate them
by | 6 views

1 Answer

0 like 0 dislike
If I understand correctly, here you have a relationship one-to-many field `post_content`.`parent_id` indicates `post`.`id`.
In order to create such a link (foreign key, FOREIGN KEY) in MySQL, you first need to ensure that both fields have the same type and size and in column `post_content`.`parent_id` no values missing in the `post`.`id`.
You then need to create the connection
ALTER TABLE `post_content` ADD CONSTRAINT FOREIGN KEY `fk_parent_id` (`parent_id`) REFERENCES `post` (`id`) ON DELETE CASCADE;

This query adds foreign key `fk_parent_id` with the fields `parent_id` and `post`.`id` and says that when you delete a record from table `post` will remove the associated records from the `post_content`.
by

Related questions

0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Sep 1, 2019 by RaymanPy
110,608 questions
257,186 answers
0 comments
35,430 users