When inserting records to a database table which has a 1:m relationship to another table, is it not best practise to ensure that the related table is updated (inserted) with a new record? Is there any consequence if just one of the related tables is updated?
Also, if I update the table on the m side of the relationship (for example, a relationship of cars and wheels where one car can have many wheels but a wheel can only belong to one car), should I always insert the foreign key as an explicit parameter? E.g. if the other related table has a PK system of 1, 2, 3, 4, 5 and going up in a unique fashion, should I just insert the foreign key value as a value through a stored procedure?
EDIT: This sounds very n00bish but unfortunately I have only learnt/learning database design and Sql Server in particular from self practise (no formal training).
Let’s use your example..
If your first question is asking if you should ensure that there is a corresponding row in the
cartable when you insert a record into thewheeltable, then yes! In reality, if your RDBMS is set up correctly with foreign keys, then you won’t be able to insert a row into thewheeltable without a parent row incar.I think this may address your second question too. If not, could you elaborate?