Databases and the single responsibility principle

databasedatabase-designsingle-responsibilitysolid

Can the single responsibility principle be applied to databases? relational databases I mean.

I'm asking this because a typical database will have several tables and we may find something like that between them:

  • Tables handle ACL and permissions.
  • Tables handle user authentication.
  • Tables relating to cron jobs and scheduled tasks.
  • Tables relating to the domain itself.
  • Tables relating to emails and invitations and so on.
  • Look ups.

Moreover the tables relating to the domain might be divided according to the application module they back up.

In code we usually divide our code base to modules/packages/namespaces, but that concept is absent from relational databases as far as I know.

so what I'm asking should the database be divided somehow to smaller databases? or maybe database (modules?!) Or should we just lump everything together and hope for a good naming convention if any?!

Best Answer

I think that the SRP translates directly to the principles of orthogonal design and full normalization in relational databases.

If you recollect that SRP states that there there should never be more than one reason for a class to change then the analogy becomes immediately apparent.

However, whether the database should be split into multiple smaller databases is an orthogonal issue, which is more of interest for pracical reasons then logical.

Related Topic