There are 3 entities:
- User - describes common attributes
- Category - individual
- Category - legal entity
How to organize data integrity restriction correctly so that User can only be in one category?
The following comes to mind:
Hang triggers on categories, so that when adding a user to a category, the opposite category is checked for the presence of the user in 1 of the categories
Create a procedure in which, within a single transaction, records will be created in: User + Legal entity or User + Individual
What is most true and are there any other ways?
CHECK (CASE WHEN fk1 IS NULL THEN 0 ELSE 1 END + CASE WHEN fk2 IS NULL TNEN 0 ELSE 1 END = 1)
(this if the user must fall into one of two categories). In general, the most correct way is not to modify the records in the tables manually, and provide the necessary logic with stored procedures. - Yaant