(I'm using SQL Server 2008 R2 but I'm not sure that's important)
If I have the following "base" tables:
SettingTypeCategory
- SettingTypeCategoryId (PK)
- CategoryName
SettingType
- SettingTypeId (PK)
- SettingTypeCategoryId (FK)
- SettingName
And I want to create multiple "custom" settings and categories like so:
CustomSettingTypeCategory
- CustomSettingTypeCategoryId (PK)
- SettingTypeCategoryId (FK)
- CustomCategoryName
CustomSettingType
- CustomSettingTypeId (PK)
- CustomSettingTypeCategoryId (FK)
- SettingTypeId (FK)
- CustomSettingValue
EDIT:
What's the best way to ensure that all CustomSettingTypes with the same CustomSettingTypeCategoryId are of the same SettingTypeCategoryId (FK to SettingType.SettingTypeCategoryId) as the CustomSettingTypeCategory.SettingTypeCategoryId?
I could add a SettingTypeCategoryId to the CustomSettingType table and have a combined FK to the CustomSettingTypeCategory table but this approach makes me cringe a little because it's redundant, you know what Category a CustomSetting belongs to through it's FK relationship to SettingType, but other than using a trigger I don't see any other way around it.