So let's talk about begin and code blocks
So in SQL, we use begin and code blocks to define a statement block, which
is really a series of SQL statements that run together. Sometimes a statement block is also called a batch
The usage will become more apparent when we start talking about if, else
But consider this for now. If a statement's a sentence, think of a begin and end
as the ability to define paragraphs. They allow us to define groupings
of statements that would make sense to run together. For instance, here you'll see an example of some statements
where we are declaring two variables that we are then printing. We're declaring a as 10 and b as 20
and we're adding them together. And they're within a code block. There's a beginning of the block with a begin
and there's the end of the block with an add. These statements will run in sequence
starting at the beginning of the begin block all the way to the end. To promote readability, it's best practice
to indent the code within the block. Again, these blocks later on are used
to help build other constructs like if, then, as well as while loops
That's where we're really going to start seeing them shine, because with those types of statements
they will need to use the block to understand what statements are run within them
That's where we'll start to see blocks. And I'll see you in the next session
and we will start to use begin, ends, then