1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Insert into one to many

Discussão em 'Outras Linguagens' iniciado por Stack, Janeiro 27, 2021.

  1. Stack

    Stack Membro Participativo

    I cannot understand how to insert into two tables that are related to each other in a one to many relationship

    for example : There is a student table and there is a sports table, a student can be only in one sport and the sport can have many students, one to many relationship established

    This is all purely hypothetical just made up to bring out an answer and is not being used for design i know its a many to many relationship between the sports and the students table

    [​IMG]

    the photo makes it clearer, a student must be in one or no sports, a sports must contain at least one or more than one (which is many) relationship, the sports id is referenced in the student table as a foreign and not a second primary key

    [​IMG]

    the data filled in should look like this, again this is purely hypothetical all of this was manually filled in and then connected, this is just to know how to carry out the process

    The main problem is I have 100k records with varying different problems and this has persisted for long, so I have ignored and and worked on other stuff, but this has to end

    My only problem is while creating a new record and inserting it into the database

    [​IMG]

    Create :

    How do you Insert Data into using the above form, into the two related tables, in the above form student information is filled in normally with their sport being spelled out like Basketball, with all the validation in place how is the data supposed to be inserted into the right place


    • as basketball already exists, and the User1 physically types through the keyboard in basketball, how is it supposed to recognize the correct corresponding number and insert it into the foreign key Field in the Main Student Table, which has a Foreign key as "sports_sport_ID"


    • what if we inserted Golf, it doesn't exist, how is it supposed to check for it existence and then insert into the table of the sport, and wire up its id to its corresponding Student

    I do not care for the way of implementation C#, WPF/XAML. Dapper, SQL , if it works that's fine by me

    Continue reading...

Compartilhe esta Página