I'm a big fan of data integrity when it comes to database. My way of thinking is :
- It's better to enforce the constraint directly in the database (example : foreign key) than either waiting for the application to crash because the row didn't exist in the table or manually adding this constraint everywhere in the code of the application.
The problem
We have a few tables that are duplicated in multiple databases and used by multiple applications. One example is the User
table.
We have users in nearly all applications. The issue is that those users are treated separately at the moment while they should, at least I think, be all group up together. Currently, there is many duplicates all over the place and outdated information about user everywhere. When a user is updated in one database/application it is not updated in the other one, but it's the same user so his information should be updated everywhere.
What we are planning to do
We were thinking about creating a reference database to regroup all this information. For example, all the information about users would be store in the same database and every application could use this database to access the information they need about their user.
Question 1 : Is this a good idea? Is there other alternative to avoid duplicate/outdated data all over the place?
The new problem
While grouping all the user information into a single database could fix the problem of duplicate/outdated user information, this create a new problem about data integrity :
- We can no longer create foreign key constraint on the
User
table since it's located in another database.
Sure, the user tables are easy to access with views but you can't apply foreign key constraint on view either...
Question 2 : So, what are my options if I would like to keep the data integrity constraints directly into the database?