Answer the question
In order to leave comments, you need to log in
How to link tables in SQL?
Good evening. There is such a database structure:
Question: how to connect tables in the MySQL Command Line Client through the Organizations_services linking table by the service_id and org_id fields? For this purpose it is necessary to make these fields secondary keys? Or just through REFERENCE you can somehow set the link?
The bottom line is that I don’t need to get data from these tables yet, I just need to make a connection between them so that the fields of the linking table are also filled in as data appears in the other two tables.
Thank you in advance for your response.
Answer the question
In order to leave comments, you need to log in
Using FOREIGN KEY Constraints
ALTER TABLE `Услуги_предприятий`
ADD CONSTRAINT `<CONSTRAINT_NAME1>` FOREIGN KEY (`org_id`) REFERENCES `Предприятия` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
ADD CONSTRAINT `<CONSTRAINT_NAME2>` FOREIGN KEY (`service_id`) REFERENCES `Список_услуг` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question