You are on page 1of 2

10/5/13

Difference Between Store Procedure with View/Triggers/Functions

11th October 2012

Difference Between Store Procedure with View/Triggers/Functions

Store Procedure and View View - A View in simple terms is a subset of a table. It can be used to retrieve data from the tables, Insert, Update or Delete from the tables. The Results of using View are not permanently stored in the database. Stored Procedure - A stored procedure is a group of SQL statements which can be stored into the database and can be shared over the netwrok with different users.

---------------------------------------------------------------------------------------------------------Store Procedure and Trigger 1) We can execute a stored procedure whenever we want with the help of the exec command, but a trigger can only be executed whenever an event (insert, delete and update) is fired on the table on which the trigger is defined. 2) We can call a stored procedure from inside another stored procedure but we can't directly call another trigger within a trigger. We can only achieve nesting of triggers in which action (insert, delete and update) defined within a trigger can initiate the execution of another trigger defined on the same table or different table. 3) Stored procedures can be scheduled through a job to execute on a predefined time, but we can't schedule a trigger. 4) Stored procedure can take the input parameters, but we can't pass the parameters as an input to a trigger. 5) Stored procedures can return values but a trigger cannot return a value. 6) We can use the Print commands inside the stored procedure to debug purpose but we can't use the print command inside a trigger. 7) We can use the transaction statements like begin transaction, commit transaction and rollback inside a stored procedure but we can't use the transaction statements inside a trigger. 8) We can call a stored procedure from front end (.asp files, .aspx files, .ascx files etc.) but we can't call a trigger from these files. -----------------------------------------------------------------------------------------------------------Store Procedure and Functions UDF can be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section where as Stored procedures cannot be.
hi5myit.blogspot.in/2012/10/different-between-store-procedure-with.html 1/2

10/5/13

Difference Between Store Procedure with View/Triggers/Functions

1)UDFs that return tables can be treated as another row set. This can be used in JOINs with other tables 2) Inline UDFs can be thought of as views that take parameters and can be used in JOINs and other Row set operations. 2)UDF-can be used with Select statement. Not returning output parameter but returns Table variables. You can join UDF. 3 Can not be used to change server configuration 4. Can not be used with XML for clause. 5.Can not have transaction within function 1)SP-Have to use EXEC or EXECUTE to Return output parameter. 2can create table but wont return Table Variable and we can not join SP. 3)Can be used to change server configuration 4.Can be used with XML FOR Clause. 5.Can have transaction within SP. 1 Stored 2 Stored 3 Stored 4 Stored 5 Stored 6 Stored procedures does not return any data and they can not be used in expressions. procedures only takes data constants as input parameters. procedures support output parameters. procedures take a parameter's default value, if it is not specified in the calling statement. procedures are called with no parenthesis to include parameters. procedures can be created locally and temporarily.

1 User defined functions does return data and they can be used in expressions. 2 User defined functions can take data constants and expressions as input parameters. 3 User defined functions do not support output parameters 4 User defined functions take a parameter's default value, if it is specified with the keyword DEFAULT in the calling statement. 5 User defined functions are called with parenthesis to include parameters. Empty parenthesis is needed if no parameters. 6 User defined functions can not be created locally and temporarily. Posted 11th October 2012 by Binita Adhikari

hi5myit.blogspot.in/2012/10/different-between-store-procedure-with.html

2/2

You might also like