T-SQL/ PL/Sql:-
T-SQL programs are two types
i) Anonymous block
ii) Sub-Programs.
Anonymous block
-------------------------
An Anonymous block is a code block i.e defined at a particular point of time for particular client mechanism.
Sub-Programs:
---------------------
A Sub-Program as a named of block of code which can be saved to the server and it can be called from any client mechanism when ever its required. Sub-Programs can be defined in 3 ways:
1) Stored Procedure
2) Stored Function
3) Trigger.
Declaring variables in the T-SQL Programs :-
-------------------------------------------------------------
Syntax : -
Declare @<variable_Name> <type> [(Size)][----------n].
Ex:-
Declare @x int;
Declare @a varchar(50), @b varchar(25);
Printing Values :-
Syntax:-
print @<var>|<value>
Ex:-
Declare @x int;
set @x=100;
print @x;
ex:-
print 'hello';
This is the extension of SQL providing High level programming capabilities. SQL does not provide the following :-
1) Step by step execution the code.
2) Condition branching and condition looping.
3) Error handling mechanism.
To overcome these problem SQL was added with procedure process capabilities and introduce as PL/SQL or T-SQL.
T-SQL is all about programming providing :-
-> Step by step execution the code.
-> Condition branching and condition looping.
-> Structure error handling mechanism through try-catch block.
T-SQL programs are two types
i) Anonymous block
ii) Sub-Programs.
Anonymous block
-------------------------
An Anonymous block is a code block i.e defined at a particular point of time for particular client mechanism.
Sub-Programs:
---------------------
A Sub-Program as a named of block of code which can be saved to the server and it can be called from any client mechanism when ever its required. Sub-Programs can be defined in 3 ways:
1) Stored Procedure
2) Stored Function
3) Trigger.
Declaring variables in the T-SQL Programs :-
-------------------------------------------------------------
Syntax : -
Declare @<variable_Name> <type> [(Size)][----------n].
Ex:-
Declare @x int;
Declare @a varchar(50), @b varchar(25);
Assigning the values in the variable:-
There are two type of values assign in the variable in T-SQL
program.
i)
We can assign a Static value to a variable
ii)
We can also assign a value of table column into
a variable.
Assign Static Values:-
-----------------------------
Syntax:-
Set
@<variable_Name> = <value>;
Ex:-
Set @x=100;
Assign Values of a Table Column:-
--------------------------------------------
Syntax:-
Select
@<variable_name> = <Column_name>, @<variable_name2> = <column_name2>--------[n] from <table_name>
[<clauses>]
Ex:-
Select @a=ename,
@b=job from emp where empno=1001
Printing Values :-
Syntax:-
print @<var>|<value>
Ex:-
Declare @x int;
set @x=100;
print @x;
ex:-
print 'hello';
No comments:
Post a Comment