Using views as a data interface between modules in a database Using views as a data interface between modules in a database database database

Using views as a data interface between modules in a database


Is this something that is sometimes done?

Yes, views are often used to insulate things from data models in a state of flux.

On a technical side, as I understand views can't have primary keys - how would I then address such a view?

MySQL doesn't support materialized views. Non-materialized views are just prepared SQL statements - they don't exist in the data model, and performance is ultimately based on what exists on the underlying table(s) and query optimizations.

That said, layering views (creating a view that selects from another) is not recommended - it's brittle, and there's a big risk that performance will decrease because someone wants simplicity over query optimization.


This is a valid approach, though you should of course be careful:

  • Make sure that your queries are very well tested for performance with query plans analyzed. The views will use the underlying tables's indexes, BUT the likelyhood of bad execution plan is higher.

  • Make sure that enough views exist to cover all needed info.