What is the maximum flexibility and why? Using db views, db tables stored by proc. and objects in tables

I want to know what is best used to use db views, db tables stored by proc. and objects in tables ... Which ones are more flexible and why, can you explain?

+4
source share
2 answers

Each tool has its own capabilities . Your choice will depend on the nature of the application, its security requirements, performance and maneuverability.

Nowadays, many programmers use data access levels ( DALs ) for this kind of thing. Many DALs allow you to specify views and stored procedures to invoke. But you can also directly run table queries without having to store stored procedures or views.

If you are not using a database of objects, you will use tables , not objects. Most applications currently use table-based database systems because they are so common and you can use DAL to control object-relational impedance mismatch .

Stored procedures are used when high performance is required, and program things must be executed in the database itself (adding is possible, timestamp value or adding / subtracting child records). A good DAL will provide high performance without the need for stored procedures.

Views are used to control the interface between the database and the data consumer. In particular, data can be filtered for security purposes. In large database scenarios, the database administrator designs and creates tables, and manages the views and stored procedures that the user allows to use to access the data.

If you're looking for maximum flexibility, most of what you need to do can be done in DAL without the need for browsing or stored procedures. But then again, it depends on your application requirements. I would say that the larger your application and user base, the more likely that you will use views and stored procedures in your application.

+1
source

I would say that, for the most part, stored procedures are a relic of the 90s:

  • completely dependent on the database
  • poor choice of language for general-purpose programming, regardless of whether it is plpgsql, t-sql or something else
  • hard to debug
  • low scalability of the code, a problem associated with any procedural programming language.
  • code version issues

This does not mean that they (for example, triggers, views, and rules) have nothing in common: large-scale reporting and data aggregation are one example of the tasks that they handle quite well. For the rest, logic is better located at the level of business logic (service, domain objects ... independently), where various tools and more complex programming paradigms are available.

The same for views and triggers.

In particular. Java environment, JPA does much better 90 +% of the time:

  • learn one query language and apply it to any database
  • business logic is more focused, in one place of the application, BLL
  • code is easier to read and write, and easier to find people who understand it.
  • it is possible to express logic spanning multiple databases in one unit of code

... and the list goes on.

0
source

Source: https://habr.com/ru/post/1306702/


All Articles