| Author |
Message |
almasmith
Joined: 26 Jan 2010 Posts: 7
|
Posted: Wed Jan 27, 2010 12:16 am Post subject: Only Populate One of Two Foreign Keys |
|
|
I'm trying to generate data for something similar to:
CREATE TABLE Table1 (
Id int NOT NULL,
ForeignKey1 int NULL,
ForeignKey2 int NULL
)
The catch is that if ForeignKey1 is not null then ForeignKey2 needs to be null and vice-versa. Is this possible? I've embedded DLR language support into a custom generator. However, the fact that it's a foreign key would require me to access the db directly in the generator. Is there an easier way to do this? |
|
| Back to top |
|
 |
almasmith
Joined: 26 Jan 2010 Posts: 7
|
Posted: Wed Feb 03, 2010 7:02 pm Post subject: Easy solution |
|
|
Sometimes the solution is so easy we don't even think about it. No custom Iron Ruby generator needed at all. SDG has a section for running SQL scripts before or after generation, so this is what I did:
Set ForeignKey1 to allow nulls 50% of the time
Set ForeignKey2 to NOT allow nulls
Create a script to run AFTER generation that fixes it:
UPDATE Table1
SET ForeignKey2 = NULL
WHERE ForeignKey1 IS NOT NULL
That's it! |
|
| Back to top |
|
 |
|
|
All times are GMT + 1 Hour
|
| Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group