问题
I have to connect Supertype Entity Called
- Users ( User_ID (PK) , User_Password , Registration_Date , .. etc ) .
to Each one of the following entities :
- Employees ( Employee_ID (PK) , Fname , Lname , Birthdate .. etc )
- Customers ( Customers_ID (PK) , Fname , Lname , Birthdate .. etc )
- Suppliers( Supplier_ID (PK) , Fname , Lname , Birthdate .. etc ) ..
How To Do It ( For relational database ) Using Ms-Access ?
回答1:
There are generally 3 strategies for representing inheritance in the relational databases:
- Everything in one table.
- Concrete types in separate tables.
- All types in separate tables.
The (3) is probably most common and most "clean" even though it can involve a fair bit of JOINing. In your case, you'd have FKs in child tables (referencing the parent) and enforce the presence1 and exclusivity2 of the child through the application logic. It is possible to enforce these things declaratively through the DBMS supporting circular and deferred FKs, but not in MS Access.
You might want to take a look at this post for more info.
1 So user cannot be just user - it must be either employee, customer or supplier.
2 So user cannot be (for example) a customer and a supplier at the same time.
来源:https://stackoverflow.com/questions/12050849/connecting-supertype-subtype