This section will be dedicated to explaining all the essential elements to handle encoding multiple Transact-SQL statements within a block of code. We will see, among other things: the use of variables, the specification of the type of calculation through operators and the most important flow control structures
Variables are objects that store values to retrieve and use in other statements. They are often used in control flow structures, stored procedures, cursors, scripts, and batches.
The operators are symbols that specify the type of calculation that the different expressions perform. We will review the different equality and conditional SQL operators
BEGIN END statement
BEGIN END are flow control structures to contain several statements grouped in a given code block. In short, they allow a series of instructions to be executed together
IF...ELSE conditional statement
IF...ELSE are flow control structures to validate conditions in the instructions of one or more statements
WHILE is a flow control structure that allows statements to be executed in a loop as long as the condition it validates is 'TRUE'
Error handling is a fundamental aspect in the management of Transact-SQL code, which allows us to control our code flow and detect problems and errors to facilitate their resolution or information
A transaction can be defined as a set of instructions that work as a unit, where if one part fails, the whole process fails in its entirety, reverting all the changes produced in the database
A cursor is a data structure that allows you to go through the set of rows returned by a SELECT and process each record one by one