Foreign keys referencing values inserted in the same project

The simplest way to populate your database with test data.

Moderators: JonathanWatts, David Atkinson, Anu Deshpande, Michelle Taylor, Lionel, Emma A, sherr

Foreign keys referencing values inserted in the same project

Postby tilo23 » Thu Feb 16, 2012 1:21 pm

I am not sure of how the foreign key generator behaves if it references column also being generated in the same project. i.e.
Assume the Project generates data for Table_1 and Table_2.
Column_A from table Table_1 has a foreign key referencing Column_B in Table_2.
If I run the project, will the Column_A be populated with values being inserted into Column_B, or will it pass to Column_A values existing in Column_B before insertion?

Is there any difference for this case between native foreign key and manually set foreign key generator?
Inside the Dilbert's world
tilo23
 
Posts: 19
Joined: Thu Dec 22, 2011 3:56 pm
Location: Berkshire, UK

Postby Brian Donahue » Fri Feb 17, 2012 4:46 pm

Hello,

From what I can tell, SQL Data Generator selects values from the primary key column of the source table to use as data in the column in the other side of the foreign key relationship. This seems to be independent of the PK value generation, otherwise you could not remove the source table containing the PK column from the project.

There is a good description of how the FK generator works here: http://www.red-gate.com/supportcenter/c ... generators

In situations where you don't have an FK constraint in the database or where the FK is a simple 1:1 relationship, you can switch to the foreign key (manual) generator. Otherwise you have no choice but to use the automatic FK generator.
Brian Donahue
 
Posts: 6670
Joined: Mon Aug 23, 2004 10:48 am

Postby tilo23 » Mon Feb 20, 2012 1:29 pm

Thanks for the clarification.
Inside the Dilbert's world
tilo23
 
Posts: 19
Joined: Thu Dec 22, 2011 3:56 pm
Location: Berkshire, UK


Return to SQL Data Generator 2

Who is online

Users browsing this forum: No registered users and 0 guests

cron