How can I create a sql database with two to many relation? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I create a sql database with two to many relation?

Well Im making a database for my windows app that save the datas about lamp and wire. Wire have to connect to two elements like battry and lamp. So I need two to one relation not many to many. What should I do?

26th Jul 2021, 3:39 AM
Code Land
Code Land - avatar
2 Answers
0
You could use one-to-many relation Use a foreign key on the many side of the relationship linking back to the "one" side: e.g teachers: teacher_id, first_name, last_name # the "one" side classes: class_id, class_name, teacher_id # the "many" side
26th Jul 2021, 5:15 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
0
Actualy its not many to one. Its many to many. Lamp can connect to many wires. Forexample one of them connects to battry another one connects to Resistor and also a wire can connect to two objects(battry and lamp). So its many to many but many to two. I mean we have to save two objects on it. First one is the first object like battry and the other one is the end point like lamp. Is there any many to two relations?
26th Jul 2021, 5:44 AM
Code Land
Code Land - avatar