.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Interview Question >> Sql Server >> Post New Question Subscribe to Interview Questions

differences between stored procedures and functions:

Posted By :Mallikarjuna Chigicherla     Posted Date :August 08, 2010    Points :10   Category :Sql Server 
Functions
----------
1) can be used with Select statement
2) Not returning output parameter but returns Table variables
3) You can join UDF
4) Cannot be used to change server configuration
5) Cannot be used with XML FOR clause
6) Cannot have transaction within function

Stored Procedure
-----------------
1) have to use EXEC or EXECUTE
2) return output parameter
3) can create table but won't return Table Variables
4) you can not join SP
5) can be used to change server configuration
6) can be used with XML FOR Clause
7) can have transaction within SP

You can also find related Interview Question to differences between stored procedures and functions:  below: 

What are the differences among batches, stored procedures, and triggers?

  

Batch:
------
A batch is a group of one or more SQL statements. SQL Server compiles the statements of a batch into a single executable unit, called an execution plan. The statements in the execution plan are then executed one at a time.

stored procedure :
------------------
A stored procedure is a group of SQL statements that is compiled one time and can then be executed many times.

trigger:
--------
A trigger is a special type of stored procedure that is not called directly. Trigger is fired each time row is affected by Insert, Update or Delete command.


(More...)

Difference between stored procedures and functions ?

  
1>Procedure can return zero or n values whereas function can return one value which is mandatory.

2>Procedures can have input,output parameters for it whereas functions can have only input parameters.

3>Procedure allow select as well as DML statement in it whereas function allow only select statement in it.

4>Functions can be called from procedure whereas procedures cannot be called from function.

5>Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.

6>We can go for transaction management in procedure whereas we can't go in function.

7>Procedures can not be utilized in a select statement whereas function can be embedded in a select statement. (More...)

How LINQ is beneficial than Stored Procedures?

  
There are couple of advantage of LINQ over stored procedures.

1. Debugging - It is really very hard to debug the Stored procedure but as LINQ is part of .NET, you can use visual studio's debugger to debug the queries.

2. Deployment - With stored procedures, we need to provide an additional script for stored procedures but with LINQ everything gets complied into single DLL hence deployment becomes easy.

3. Type Safety - LINQ is type safe, so queries errors are type checked at compile time. It is really good to encounter an error when compiling rather than runtime exception! (More...)

How LINQ is beneficial than Stored Procedures?

  
There are couple of advantage of LINQ over stored procedures.

1. Debugging - It is really very hard to debug the Stored procedure but as LINQ is part of .NET, you can use visual studio's debugger to debug the queries.

2. Deployment - With stored procedures, we need to provide an additional script for stored procedures but with LINQ everything gets complied into single DLL hence deployment becomes easy.

3. Type Safety - LINQ is type safe, so queries errors are type checked at compile time. It is really good to encounter an error when compiling rather than runtime exception! (More...)

why use stored procedures ?

  
* Execution plan retention and reuse
* Query auto-parameterization
* Encapsulation of business rules and policies
* Application modularization
* Sharing of application logic between applications
* Access to database objects that is both secure and uniform
* Consistent, safe data modification
* Network bandwidth conservation
* Support for automatic execution at system start-up
* Enhanced hardware and software capabilities
* Improved security
* Reduced development cost and increased reliability
* Centralized security, administration, and maintenance for common routines (More...)

How many types of Stored Procedures are there in Sql Server?

  
1. User Defined Stored Procedures.
a. Transact-SQL stored procedure
b. CLR Stored Procedure.

2. System Stored Procedures (More...)

What are Beninese of stored procedures?

  
- improve performance of application
- Reduce traffic
- Promote code reuse (More...)

Why use Stored Procedures ?

  
Stored procedures allow a lot more flexibility offering capabilities such as conditional logic
Stored procedures are stored within the DBMS, bandwidth and execution time are reduced
Client developers are abstracted from complex designs
(More...)

What are the differences between Stored procedure and function.

  
Below are the main differences between stored procedure and functions-
1.Function has a return type but Stored procedure doesn't have a return type.
2.Stored Procedure supports IN/OUT/IN-OUT Parameters while function supports only IN parameters.
3.Stored procedure can contain all the DML(Select,update,insert,delete) statements but function can contain only select statement.
4.Function can be called from a stored procedure but stored procedure cannot be executed from a function.
5.For Exception Handling, the stored procedure can contain try---catch block but Function doesn't support try---catch block.
(More...)

What are System Stored Procedures?

  
These are special type of Stored Procedures created in MASTER database and accessible in any other database within the server. Rules to create System Stored Procedures:
Name should start with SP_
Should be created in MASTER database only (More...)

Where are shared assemblies stored in .NET?

  
Shared Assemblies are stored in Global Assembly Cache also known as GAC. (More...)

What is the differences between delegates and interfaces?

  
Interfaces carry semantics, and when a programmer implements an interface, he is typically well aware of that semantics. When you try to invoke a particular method via an interface, you can be fairly certain that if you succeed, the semantics of that method is what you expect. For that reason, using interfaces is essentially doing a check for semantic correctness on some level.


Delegates, on the other hand, by only verifying the method signature, make the programmer responsible for ensuring that the semantics of the method is compatible. The semantics may cover not only the meaning of the arguments and return value (some times even the order of the arguments if they are of the same type), the ranges of the arguments, but also an invocation order when multiple methods are concerned. Hence, in a sufficiently large program there is plenty of margin to make an error when different programmers are not forced to comply with a uniform semantics (as they would be if interfaces were used). (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

 
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.


Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend