How to add linked data?
Posted: Mon 05 Oct 2015 22:15
I have two tables that are linked by a foreign key.
Table_A
Id, PK, AUTO_INCREMENT
Date, IX
Table_B
A_Id, PK, Foreign Key Table_A, Id
Id, PK
Value
I want to append to the destination two sets of the data from the source. Suppose
In source:
Table_A
{ 30, '2015-09-01' }
Table_B
{ 30, 1, "<src>" }
In Destination
Table_A
{ 30, '2015-08-31' }
Table_B
{ 30, 3, "<some stuff>" }
Comparing the index on Date, source has data that the destination does not have even though the primary keys are the same. What I'd like the software to do automatically is
INSERT INTO Table_A (Date) VALUES ('2015-09-01')
// get the new primary key, name it @pkA
INSERT INTO Table_B VALUES (@pkA, 1, "<src>")
How can I do this?
Table_A
Id, PK, AUTO_INCREMENT
Date, IX
Table_B
A_Id, PK, Foreign Key Table_A, Id
Id, PK
Value
I want to append to the destination two sets of the data from the source. Suppose
In source:
Table_A
{ 30, '2015-09-01' }
Table_B
{ 30, 1, "<src>" }
In Destination
Table_A
{ 30, '2015-08-31' }
Table_B
{ 30, 3, "<some stuff>" }
Comparing the index on Date, source has data that the destination does not have even though the primary keys are the same. What I'd like the software to do automatically is
INSERT INTO Table_A (Date) VALUES ('2015-09-01')
// get the new primary key, name it @pkA
INSERT INTO Table_B VALUES (@pkA, 1, "<src>")
How can I do this?