sql server - SQL Table Integrity -
i'm using sql server 2014 i'm looking design solution.
i have 3 tables need connect ensure integrity. i'm removed tables , columns sake of clarity.
group parent of type.
group: widgets types: blue widgets, red widgets
i want store data @ group/category level, instance:
group: widgets categories: widgets men, widgets women
categories should contrained @ type level
type: blue widgets category: widgets men type: red widgets category: widgets women
therefore i'm trying ensure data enter typecat valid in category , type's group exist in groupcat.
i'm sure there kind of pattern this, non db guy, i'm not sure how work out.
at risk of spending far time on question, i'm going try show how difficult untangle. use thicket of abstract nouns -- type, category, group -- in varying combinations. change nomenclature between illustrated tables , question text. don't state keys are. make declarations, , expect reader make right associations , inferences.
group parent of type.
so groupid
identifies grouptype
; grouptype has typeid. anyway, that's how i'd interpret "parent".
categories should contrained @ type level
i wasn't able make sense of given next statement:
ensure data enter typecat valid in category , type's group exist in groupcat
not sure "that" category is, rule seems
typecat.typeid exists in grouptype.typeid grouptype.groupid exists in groupcat.groupid
but said
i want store data @ group/category level
which seem imply new data coming left, were, , new rows in groupcat
must meet constraints:
groupcat.groupid exists in grouptype.groupid -- opposite above groupcat.catid exists in typecat.catid {groupcat.groupid,typecat.typeid} exists in grouptype
those rules can expressed in sql, i'm not sure should. , i'm not sure they're intend. i'm throwing darts and, if not blindfolded, let's lighting leaves desired.
in general, statement a must have b
in sql means there table b representing domain of values of type, , foreign key on column in values must come domain. logic, there should tables groups, categories, , types in model. pattern of last rule above -- 2 tables must joined determine if meet third domain -- occur, rarely. when crops up, it's cause things on , ensure model reflect reality.
Comments
Post a Comment