Search code examples
c#sql-serverstored-proceduresormpreferences

When to use Stored Procedures instead of using any ORM with programming logic?


Hi all I wanted to know when I should prefer writing stored procedures over writing programming logic and pulling data using a ORM or something else.


Solution

  • Stored procedures are executed on server side.

    This means that processing large amounts of data does not require passing these data over the network connection.

    Also, with stored procedures, you can build consistent complicated business logic.

    Say, you need to update the account balance each time you insert a transaction, and you need to insert many transactions at once.

    Instead of doing this with triggers (which are implemented using inefficient record-by-record approach in many systems), you can pass a table variable or temporary table with the inputs and issue a set-based SQL statement inside the procedure. This will be much more efficient.