Differences among batches, stored procedures & triggers

What are the differences among batches, stored procedures, and triggers?

A batch is a group of one or more SQL statements. SQL Server compiles the statements of a batch into a single executable unit, called an execution plan. The statements in the execution plan are then executed one at a time.

A stored procedure is a group of SQL statements that is compiled one time and can then be executed many times.

A trigger is a special type of stored procedure that is not called directly. Trigger is fired each time row is affected by Insert, Update or Delete command.

What are the differences among batches, stored procedures, and triggers?

BatchStored ProcedureTriggers
Collection or group of SQL statements. All statements of a batch are compiled into one executional unit called execution plan. All statements are then executed statement by statement.It’s a collection or group of SQL statements that’s compiled once but used many times.It’s a type of Stored procedure that cannot be called directly. Instead it fires when a row is updated, deleted, or inserted.
What are the instances when triggers are appropriate?
Scenarios for using triggers. To create a audit log of database activity. To apply business rules. To apply some calculation on data from tables which is not stored in them.....
What are the restrictions applicable while creating views?
Views can be created referencing tables and views only in the current database. ......
What are the events recorded in a transaction log?
The start and end of each transaction - Every data modification .......
Post your comment