Multi-Property Uniqueness

MartinHMartinH Posts: 82 Bronze 2
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.

Comments

  • 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
  • MartinHMartinH Posts: 82 Bronze 2
    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.
  • 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
  • MartinHMartinH Posts: 82 Bronze 2
    Peter:

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

    Thanks for the help.

    Regards,
    Martin.
Sign In or Register to comment.