Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Data Modeling - Ensuring Uniqueness over a group of rows Expand / Collapse
Author
Message
Posted Monday, May 20, 2013 8:26 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Today @ 1:51 PM
Points: 25, Visits: 2,115
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?
Post #1454788
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse