WHAT IS PAGE?
‘Page’ is
fundamental unit of Data in SQL. An each page has 8KB size. The arrangement of
continuous eight page is called as ‘Extend’. Therefore, 64KB is called as
‘Extend’.
Pages are used
for storing the Data. In other hand, I/O operations has been occurred on this
page. On the Page, the page header (96B) is followed by rows of Data. And Page
ends with Row offset in descending order.
WHAT IS INDEX?
Index is used
for retrieving Data Fast. Index is working like our book index page it contains
where the Data are stored.
Two types of indexes
are used in SQL Server.
1.
Clustered Index
2.
Non - Clustered Index
Clustered Index
:
In this Index, Data are stored
by order (providing in index definition) during insertion.
E.g.: if we create an index with descending order
of Name and Insert the names as following order:
Srinath,Mano,Pugal,Ranjith,
then you select the table it looks like,
Employee
Id
|
Name
|
Phone
Number
|
Salary
|
1
|
Srinath
|
000 000 0000
|
200000
|
4
|
Ranjith
|
333 333 3333
|
100000
|
3
|
Pugal
|
222 222 2222
|
100000
|
2
|
Mano
|
111 111 1111
|
200000
|
Non - Clustered Index:
In this Index, Data are stored
by Actual Insertion. But it Keeps row id and values separately in order of
index definition.
Each Filtration
is runs on index table then it gets the rowid and the fetch the corresponding
rows original table
Rowid
|
Value(Name column)
|
000A1
|
Srinath
|
000A4
|
Ranjith
|
000A3
|
Pugal
|
000A2
|
Mano
|
WHAT IS CURSOR?
Cursor
is used for process a single row instead of all rows at a time. Cursor gets the
result set from Select query of the Table(s). In T-SQL or Select query, all the
rows are processed as a set or unit. So, Cursor is known as ‘Performance
Killer’.
Before using the
Cursor, we must create the memory space for the Cursor and then open it too. At
last closing and decollate the memory is good one. Actually it is called as
‘Life cycle of Cursor’.
If we fetch the rows
of table (given in Table example), it looks like,
Employee
Id
|
Name
|
Phone
Number
|
Salary
|
1
|
Srinath
|
000 000 0000
|
200000
|
After fetching a
row, we can do our business logics. For example, update the Salary with 30 % of
current Salary. But, using Cursor is not
advisable.
Employee
Id
|
Name
|
Phone
Number
|
Salary
|
2
|
Mano
|
111 111 1111
|
200000
|
Employee
Id
|
Name
|
Phone
Number
|
Salary
|
3
|
Pugal
|
222 222 2222
|
100000
|
Employee
Id
|
Name
|
Phone
Number
|
Salary
|
4
|
Ranjith
|
333 333 3333
|
100000
|
WHAT IS FUNCTION?
SQL
allows to create a function, called ‘User Define Functions’ without the DDL
queries. Function only accepts the Input parameters and return value. We can
define the function as three types based on the how was returned.
Function would
be called from anywhere of the Queries (Column, System Function, ‘Where’
clause) is based on its type.
WHAT IS STORED PROCEDURE?
SP
means, storing the set of rules (steps) which will be used for Defined process.
So we can do all business logics. Means, not like Function we can do all DDL
queries and I/O variable(s) are available.
For
example, if we want to SP for Hike process with,
1.
Increase the salary by 30 % of current Salary
2. Insert
the highly paid employee(s) details into another table. Then SP looks like,
Update Table set Salary += 30 % where salary
is not null
Insert into Table values (Select max (Salary))
Employee
Id
|
Name
|
Phone
Number
|
Salary
|
1
|
Srinath
|
000 000 0000
|
260000
|
2
|
Mano
|
111 111 1111
|
260000
|
3
|
Pugal
|
222 222 2222
|
130000
|
4
|
Ranjith
|
333 333 3333
|
130000
|
Incremented Salary table of each
employee. And the highly paid employee’s details are inserted into another
table, which is following on:
Employee
Id
|
Name
|
Phone
Number
|
Salary
|
1
|
Srinath
|
000 000 0000
|
260000
|
2
|
Mano
|
111 111 1111
|
260000
|
So, if we defined the Hike (or any other)
process as a SP, then we just run that for avoiding manual errors.