SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Data Modeling - Ensuring Uniqueness over a group of rows


Data Modeling - Ensuring Uniqueness over a group of rows

Author
Message
Sam S Kolli
Sam S Kolli
SSC Veteran
SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)

Group: General Forum Members
Points: 259 Visits: 3486
What are the different ways or best practices to design this kind of data model?

Lets say there are 50 different color choices. Any number of colors can be assigned to a group, but no two groups can contain the exact same colors. For example, if Group A has {Red, Blue, Green}, then no other group can have those exact three colors only; other groups can have a subset of those three colors like {Red, Blue} or {Blue, Green} or more colors in addition to those colors like {Red, Blue, Green, Yellow} or {Red, Blue, Green, Purple} or {Red, Blue, White} but NOT {Red, Blue, Green}.

These are some of the ways I can think of:
1. Use procedure to insert rows and include logic in the proc to check uniqueness and prevent duplicates
2. Or use a trigger in a similar way
3. Or Use multiple columns, but this isnt really a robust solution; first off, the number of columns is somewhat predefined and DDL has to change if new columns have to be added; secondly, how we use the multiple columns to store which color in which column doesnt really help in ensuring uniqueness; by that I mean ColA=Green and ColB=Red is technically different from ColA=Red and ColB=Green even though they are same from a human perspective.
4.Or Have a parent-child table combination, where the parent table has one row with one column being used to store a concatenated string over a pre-defined sort order in one row (some thing like Blue|Green|Red), and the child table has the actual colors in multiple rows with each row being tied back to the appropriate parent table row; this helps, but the child table still needs to have some kind of logic to ensure uniqueness on itself.
5. Or Have an indexed view underneath the table (this is kind of inverse of the Num 5). The parent table here will have multiple rows for each color, and the indexed view will have one row with one column being used to store a concatenated string which will then participate in the Unique index.


Are there any other ways to do this?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search