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?
Batch | Stored Procedure | Triggers |
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. |