Suppose I have two tables: A and B, each with three columns (A.id, A.title, A.text and B.id, B.a_id, B.text). B.a_id is a foreign key related to A.id. Suppose that in (1, 'foo', 'bar') there is one entry and 2 entries in B (1, 1, 'test') and (2, 1, 'test1').
My question is: is there a standard way to copy a record to and at the same time copy all the records from B that belong to A. Therefore, suppose I create a new record in (2, 'foo', 'bar') based on ( 1, 'foo', 'bar'), is there any method that creates two new entries in B (3, 2, 'test') and (4, 2, test1)?
I have never used triggers before, is this the right moment to start doing this? Or is this a very stupid question?
source
share