What are the benefits of creating Stored Procedures in SQL and MySQL?

前端 未结 4 1405
遥遥无期
遥遥无期 2020-12-29 23:52

I have a theoretical question.

I can\'t see any difference between declaring a function within a PHP file and creating a stored procedure in a dat

4条回答
  •  无人及你
    2020-12-30 00:39

    Some benefits include:

    • Maintainability: you can change the logic in the procedure without needing to edit app1, app2 and app3 calls.

    • Security/Access Control: it's easier to worry about who can call a predefined procedure than it is to control who can access which tables or which table rows.

    • Performance: if your app is not situated on the same server as your DB, and what you're doing involves multiple queries, using a procedure reduces the network overhead by involving a single call to the database, rather than as many calls as there are queries.

    • Performance (2): a procedure's query plan is typically cached, allowing you to reuse it again and again without needing to re-prepare it.

    (In the case of your particular example, the benefits are admittedly nil.)

提交回复
热议问题