HTML

1.Exception Handling:
An exception is an error condition during a program execution.
By using exception block we can such type of errors.
There are two types of exceptions
   1.System defined Exception
   2.User defined Exception
Syntax:
   Declare
    //Declaration Section
   Begin Try
    //Executable Commands;
   End Try
   Began Catch
    //When exception_1 then
     Statement
    //When exception_2 then
     Statement
   End Catch;
 i. System defined Exception:
  These exceptions are predefined in sql which get raised when certain database rule is violated.
Code:
Output:
ii.User defined Exception:
  The type of exceptions that are generated by the user not by the system based on the           code.
Code:
Output:
2.Began and End:
It is mandatory section
It consists of the executable statements.
It should have at least one executable line of code.
Syntax:
Begin
Executable statements
End
3.Commit and Rollback:
Commit is used for the permanent changes.
When we use Commit in any query then the change made by that query will be permanent.
We can't rollback after commit.
Syntax:
Begin Transaction Transaction_Name
Statement
Commit Transaction Transaction_Name
i.Command:

Output:
ii.Rollback
Rollback is used to undo the changes made by any command.
But only before a commit command is done.
We can't rollback the data which has been committed in the database.
Syntax:
Begin Transaction Transaction_Name
Statement
Rollback Transaction Transaction_Name
4.Print:
Print is nothing but a return statement.
It is used to return messages to the client.
It is used for troubleshooting the code by displaying the message or variables.
Command:
Output:
Command:
Output:
5.Variables:
A variables is nothing but a name given to a storage area.
Variables must be declared in the declaration section.
variables names are valid identifier in sql.
There are two types of variables.
1.Local variable:Variable declared in inner block and not accessible to outer block.\
2.Global variable:Variable declared in the outermost block.
  Command:
Output:

6.If else:
If else statement is used to execute when a condition is true,or executes a different code if the condition evaluates to false.
Syntax:
If condition
{ statements to execute when the condition is true}
else
{ statements to execute when the condition is false}
Command:
Output:

7.While:
If the expression is true, the statement is executed continuously until the expression is false.
It again determines whether to execute the statement or not.
Syntax:
while (expression)
sql_statement;
[break]
sql_statement;
[continue]
Break: Break forces a loop to exit immediately.
If we want to stop a loop in any intermediate position then we can use break keyword.
Continue:
It is opposite of Break.
Instead of stopping the loop, It immediately loops again.It skips the rest of the code.
Command: For Break
Output:
Command: For Continue

Output:

8.Return:
Return values can be used with in the stored procedures.
It is immediate and complete and can be used at any point to exit from a procedure.
Statements that follow return are not executed.