Упрощенная структура:
Table RefType:
Код: Выделить всё
int RefTypeId PK
string Code
string Description
Код: Выделить всё
int RefItemId PK
int RefTypeId FK
string Code
string Description
Код: Выделить всё
RefTypeКод: Выделить всё
RefTypeId Code Description
--------------------------------------------------------
1 'FILESTATUS' 'Status of the file'
2 'RECORDSTATUS' 'Status of the record'
Код: Выделить всё
RefItemКод: Выделить всё
RefItemId RefTypeId Code Description
------------------------------------------------------------------------
1 1 'READY' 'The file is ready to be processed'
2 1 'PROCESSED' 'The file has been processed'
3 2 'READY' 'The record is ready to be processed'
4 2 'PROCESSED' 'The record has been processed'
5 1 'ERROR' 'The file has an error'
6 2 'FAILED' 'The record has failed processing'
Например, в таблице, в которой хранятся сведения о файлах, я хотел бы иметь внешний ключ к таблице RefItem, RefItemId столбец , но только там, где RefItem.RefTypeId == 1.
Аналогично в таблице, хранящей сведения о записях, внешний ключ к RefItem таблица, столбец RefItemId, должна быть ограничена значением RefItem.RefTypeId == 2.
Спасибо!
P.
Подробнее здесь: https://stackoverflow.com/questions/786 ... o-a-subset
Мобильная версия