Monday, July 23, 2012

Advantages of Stored Procedure in Microsoft SQL Server


There are many advantages of using stored procedures in Microsoft SQL Server. These are :
  1. Easier to maintain and troubleshoot as they are modular.
  2. Stored procedures enable better tuning for performance.
  3. While using stored procedures is much easier from a GUI end than building complex queries.
  4. Stored procedures help in reducing network usage.
  5. Stored procedures provide more scalability to an application.
  6. Reusable and hence reduce code.
  7. Stored procedures can be part of a separate layer which allows separating the concerns. Hence Database layer can be handled by separate developers proficient in database queries.


How to Code Efficient Transactions in Microsoft SQL Server

To Code efficient transactions in Microsoft SQL Server, We must take care of following things :

  1. Don't allow input from users during a transaction.
  2. Don't open transactions while browsing through data.
  3. Keep the transaction as short as possible.
  4. Use lower transaction isolation levels.
  5. Access the least amount of data possible while in a transaction.

Security Features of Stored Procedures in Microsoft SQL Server


Security features of stored procedures are available in Microsoft SQL Server. These are :
  1. Provide more granular security control through stored procedures rather than complete control on underlying data in tables.
  2. Grants users permissions to execute a stored procedure irrespective of the related tables.
  3. Grant users permission to work with a stored procedure to access a restricted set of data yet no give them permissions to update or select underlying data.
  4. Stored procedures can be granted execute permissions rather than setting permissions on data itself.


Usage of Triggers in Microsoft SQL Server


Triggers are used in Microsoft SQL Server for various purpose. These are used when :
  1. Creation of audit log of database activity.
  2. For applying business rules.
  3. For applying calculation on data from tables which is not stored in them.
  4. To enforce referential integrity.
  5. When alter data in a third party application needed.
  6. To execute SQL statements as a result of an event or condition automatically.


Restriction on Views in Microsoft SQL Server

Restrictions are applied when we create views in Microsoft SQL Server. These restrictions are listed below :

  1. Views created, only referencing tables and views in current database. 
  2. View name must not match with the name of table owned by that user.
  3. Views can be built based on other views and on procedures that reference views.
  4. We cannot associate Rules or DEFAULT definitions with views.
  5. We can only associate INSTEAD OF triggers with views.
  6. ORDER BY, COMPUTE, COMPUTE BY clauses and INTO keyword cannot be included in query that defines view.
  7. Full-text index definitions cannot be used for views.
  8. Temporary views cannot be created
  9. Views cannot be created on temporary tables.