问题
Good day, I'm designing MySQL database for a web application which has two parts:
- The first part is a member system which maintains country/organization/suborganization/user hierarchy, service parameters and user roles.
- The second part is a web application for managing orders and tasks within these orders. It will use the member system to authentificate user and get it's roles and service parameters configured for this webapp.
- In future there will be another application (and later possibly some more) for electronic auction which will use the same member system to authenticate users and get roles and service parameters for electronic auction.
All these webapps will often be used by the same organizations/users. Is it good idea to create separate schemas for each application and create foreign keys between them? For example webapp for managing orders will have it's own schema, member system will have it's own schema and tables of ordering webapp will reference tables in member schema (because an order has an owner = organization, user etc.). Later auction webapp will have it's own schema referencing tables in member system schema. What are pros and cons of such design? Or would you recommend to put it all in one schema? Please advise.
Thank you.
回答1:
You want to separate the database design for each app
- for security reasons
- to keep things tidy
- and so on
On the other hand you want to share the same table with user information and don't want to abstain from foreign key relationship. I wouldn't omit it either.
So, how about this:
Have one schema, in which you only maintain your user information. On this table(s) you put a trigger, which after an insert inserts the row into the same tables in all your other app's schemas.
So when you create a new user, you just make an entry in your members table in the main schema. It's write only. In each schema for each app you have another members table (which can be referenced by foreign keys), which is a read only table.
来源:https://stackoverflow.com/questions/25019471/should-i-create-special-schema-for-each-web-application-or-put-it-all-in-a-singl