Multi-Property Uniqueness

The simplest way to populate your database with test data.

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

Multi-Property Uniqueness

Postby MartinH » Wed Jan 11, 2012 1:51 pm

Is it possible to generate unique values for a field where the uniqueness is determined by more than one field?

For instance, I am generating sales receipts and the ticket number (integer) can't repeat when two fields coincide. The fields are ShopNumber (integer) and TillNumber (integer), so there should be no repeats for the combination ShopNumber+TillNumber+TicketNumber.

Is this possible?

Thanks,
Martin.
MartinH
 
Posts: 64
Joined: Fri Apr 15, 2005 9:13 am

Postby peter.peart » Thu Jan 12, 2012 2:37 pm

Thanks for your post. Unfortunately, It's not possible to have data generated based on relationships between columns (unless it's PK > FK).

I suppose in this instance, if the value of the integer isn't important, you could use a RegEx for each column that specified a value between certain values that was different for all columns, i.e:

ShopNumber = 1 - 2000
TillNumber = 2001 - 4000
TicketNumber = 4001 - 6000

Or something along those lines.

HTH!

Pete
Peter Peart
Red Gate Software Ltd
+44 (0)870 160 0037 ext. 8569
1 866 RED GATE ext. 8569
peter.peart
Site Admin
 
Posts: 362
Joined: Tue Sep 02, 2008 9:58 am
Location: Top floor, RG towers with the cool kids

Postby MartinH » Thu Jan 12, 2012 3:54 pm

Peter:

If this is not available off-the-shelf, could I do it with a custom generator?

If this is (in theory) possible, I will look into writing one.

Thanks,
Martin.
MartinH
 
Posts: 64
Joined: Fri Apr 15, 2005 9:13 am

Postby peter.peart » Thu Jan 12, 2012 4:10 pm

Hi Martin,

It should be possible. There's an article on our Simple Talk website which explains how to do this in more detail:

http://www.simple-talk.com/dotnet/.net- ... generator/

HTH!

Pete
Peter Peart
Red Gate Software Ltd
+44 (0)870 160 0037 ext. 8569
1 866 RED GATE ext. 8569
peter.peart
Site Admin
 
Posts: 362
Joined: Tue Sep 02, 2008 9:58 am
Location: Top floor, RG towers with the cool kids

Postby MartinH » Thu Jan 19, 2012 7:26 pm

Peter:

Yes, that will work fine. I'll write my own generator to support this scenario,

Thanks for the help.

Regards,
Martin.
MartinH
 
Posts: 64
Joined: Fri Apr 15, 2005 9:13 am


Return to SQL Data Generator 2

Who is online

Users browsing this forum: No registered users and 0 guests

cron