Answer the question
In order to leave comments, you need to log in
How to write relationships in a database schema?
When creating one table, it refers to external values from another table, that is, a many-to-many relationship is implemented using the example of users and reviews:
CREATE TABLE IF NOT EXISTS `task_force`.`users` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`reviews` INT UNSIGNED NOT NULL,
FOREIGN KEY (`reviews`) REFERENCES `reviews` (`id`),
PRIMARY KEY (`id`)
);
CREATE TABLE IF NOT EXISTS `task_force`.`reviews` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`user_id` INT UNSIGNED NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),
PRIMARY KEY (`id`)
);
Answer the question
In order to leave comments, you need to log in
If many to many, then there must also be a link table usersToReviews.
But in general this is very strange.... 10 users collectively wrote 1 review... Seriously?)
If
it's still one to many, which I suspect you meant, then:
users? It's not needed, remove it.
- How to delete, the problem will be solved by itself: first create users, and only then reviews with a link to users
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question