HTML

User Defined Functions:
Sql allows us to create our own functions called User defined functions
We can use Where Clause in user defined functions
It is of two types
    i.Scalar  Functions
    ii.Table Valued Functions
1.Scalar Function:
  Thses functions returns only a single value.
   In scalar functions it is not required to use begin and end block.
   In this we can use ant data type as return type except text,image,ntex,cursor and timestrap.
Command:
Output:

2.Table Valued Function
 A table valued function accepts zero or more parameters and  return a table variable.
 By using this we can get data from more than one table by  performing join queries.
This is Further classified into Inline table valued function and Multi statement table valued function.
i.Inline table valued function:
It contains a single statement that must be a select statement.
There is no need for begin and end block.
Command:
Output:

2.Multi-Statement table valued function
A multi-Statement table valued function contains multiple sql statements enclosed in begin and end blocks
In this the return statement is declared as a table variable and includes the full structure of the table.
The return statement is with out a value and the declared table is returned.
Command:
Output:
Scalar Function example:
Command:
Output:
Ex-2: write a table valued function to print a table.
Command

Output:


View:
A view is nothing but a virtual table which is stored in the database with associated name,
A View can contain all rows of a table or select rows of a table.
Views does not have any physical storage so they do not contain any data .
It contains data from more than one table.
Syntax:
Create view View_Name
as 
sql statement
where condition
Command:

Output:
Command: For customer and product detais
Output:
Sql Commands:
sql commands are nothing but instructions which are used to perform specific tasks like insertion,deletion,update etc.
Sql commands are classified into 4 types
1.Data Definition Language(DDL):
These are used for creating and dropping the structure of the database.
These commands are Create,Drop,Rename and Truncate.
2.Data Manipulation Language(DML):
These are used for Storing,Retrieving,Modifying and deleting the data.
These commands are Select,Insert,Updating and Delete.
3.Transaction Control Language(TCL):
These sql commands are used for Managing the changes affecting the data.
These commands are Commit,Rollback and Save point.
4.Data control Language(DCL):
These are used to provide security to database objects.
These Commands are Grant and Revoke