0% found this document useful (0 votes)
20 views1 page

Creating Function: Create NOT Null NOT Null NOT Null NOT Null NOT Null Constraint Primary KEY

This document discusses SQL functions and stored procedures. It provides an example of creating a SQL function to calculate salary by subtracting 10% from the basic salary. It also creates a table to store employee salary data and lists key differences between functions and stored procedures - functions must return a value, can only have input parameters, and can be called from procedures while procedures can have input/output parameters and allow DML statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

Creating Function: Create NOT Null NOT Null NOT Null NOT Null NOT Null Constraint Primary KEY

This document discusses SQL functions and stored procedures. It provides an example of creating a SQL function to calculate salary by subtracting 10% from the basic salary. It also creates a table to store employee salary data and lists key differences between functions and stored procedures - functions must return a value, can only have input parameters, and can be called from procedures while procedures can have input/output parameters and allow DML statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

Creating function

Create function calSalary (@basicSalary money)

return money

as

begin

return (@basicSalary- @basicSalary*0.1)

end

Calling function

Select dbo. calSalary(150000)

2. CREATE TABLE EmpSalary (


EmpNo int NOT NULL,
Month varchar(20) NOT NULL
BasicSalary moneyNOT NULL,
EPF decimal (1,1) NOT NULL,
NetSalary moneyNOT NULL
CONSTRAINT PK_Empsalary PRIMARY KEY (EmpNo)
);

3.
1. Function must return a value but in Stored Procedure it is optional( Procedure can
return zero or n values).
2. Functions can have only input parameters for it whereas Procedures can have
input/output parameters .
3. Functions can be called from Procedure whereas Procedures cannot be called from
Function.
4. Procedure allows SELECT as well as DML(INSERT/UPDATE/DELETE) statement in it
whereas Function allows only SELECT statement in it.
5. Procedures can not be utilized in a SELECT statement whereas Function can be
embedded in a SELECT statement.
6. Stored Procedures cannot be used in the SQL statements anywhere in the
WHERE/HAVING/SELECT section whereas Function can be.

You might also like