1. Difference between Primary Key and Unique Key
SN.
|
Primary Key
|
Unique Key
|
1
|
Only one Primary key allowed
in a table.
|
More than one unique key allowed
in a table
|
2
|
By default, Primary key is
clustered index and data in the database table is physically organized in the
sequence of clustered index.
|
By default, Unique key is
non-clustered index.
|
3
|
Primary Key can't accept null values.
|
Unique key can accept only one null
value.
|
4
|
Primary key can be made
foreign key into another table.
|
Unique key can't be made
foreign key into another table.
|
2. Difference between Stored Procedure and
Function
|
SN.
|
Function
|
Procedure
|
|
1
|
Function must return a value.
|
Stored Procedure it is optional
|
|
2
|
Functions can have only input parameters for it
|
Procedures can have input/output parameters.
|
|
3
|
Function takes one input parameter it is mandatory
|
Stored Procedure
may take o to n input parameters.
|
|
4
|
Functions can be called from Procedure
|
Procedures
cannot be called from Function
|
|
5
|
Function is compiled and
executed every time it is called.
|
Stored Procedures are pre-compile objects which are compiled for first time and its
compiled format is saved which executes (compiled code) whenever it is called
|
|
6
|
Function allows only SELECT statement in it.
|
Procedure allows
SELECT as well as DML (INSERT/UPDATE/DELETE) Query.
|
|
7
|
try-catch block cannot be used in a Function.
|
Exception can be
handled by try-catch block in a Procedure
|
|
Other Differences
1. Stored Procedures cannot be used in the SQL statements anywhere in the
WHERE/HAVING/SELECT section whereas Function can be.
2. Functions that return tables can be treated as another rowset. This can
be used in JOINs with other tables.
3. Inline Function can be thought of as views that take parameters and can
be used in JOINs and other rowset operations.
4. We can go for Transaction Management in Procedure whereas we can't go in
Function.
|
||
No comments:
Post a Comment