What's the point of a stored procedure?

前端 未结 12 1026
逝去的感伤
逝去的感伤 2021-01-21 12:13

Are they useful for anything outside of a database administrator? If I understand them correctly it\'s merely queries that can be saved directly into MySQL, so it\'d be useless

12条回答
  •  北荒
    北荒 (楼主)
    2021-01-21 12:28

    Back in the 90's, stored procedures were the safest way to prevent anyone from accessing the data tables directly.

    At first hand, they were more likely to counter security issues. Secondly, they were meant to be easier to work with the data, as there were no ORM tools as today's.

    In the days, they are meant for complex transactions mainly. When I say complex, I mean something that cannot be solved with simple CRUD operations such as NHibernate or Entity Framework can do.

    So, when a stored procedure only perform a SELECT, an INSERT, an UPDATE or a DELETE, you may be right that they are now useless somehow, as you can perform these basic repeated operations through an ORM tool. However, when you have to build a report, for instance, that requires desperate information data, and some other calculations performed, etc. and that the result is pretty complex to compute, then you better let the database engine work this out as it is designed to compute such data.

提交回复
热议问题