ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
Differences between functions and stored procedures?
 Question Submitted By :: Srikanth
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Differences between functions and stored procedures?
Answer
# 1
1. Functions can used with Select statement
   SP are not
2. If we have a syntax error or bug in SP it ignore it at
   execution. In case of Function it won't.
3. Function should return atlease one value. 
   SP may or maynot return values.
4. Function cannot include in other function.
   We can execute one SP in other.
 
Is This Answer Correct ?    7 Yes 4 No
Avinash
 
  Re: Differences between functions and stored procedures?
Answer
# 2
UDF
1. Must return a value – a single result set
2. Directly used in select, order by,where, from
3. UDF can’t use nondeterministic function Such as
getdate(), rand()
4. Can’t change server enviroment variables
5. Stops execution of T-SQL code when error occurs
6. Can’t use temp table in UDF

Stored Procedure
1. Can return value – multiple result set
2. Can’t use in select
3. Can use nondeterministic functions
4. Can change server enviroment variables
5. Stored procedure move to the next instruction if you used
proper error handling,
6. Can use temp table in SP
 
Is This Answer Correct ?    6 Yes 2 No
Paras
 
 
 
  Re: Differences between functions and stored procedures?
Answer
# 3
store procedure takes less time to execute the statement 
than functions, also we can create loops inside the store 
procedure.
 
Is This Answer Correct ?    3 Yes 0 No
Santhoshkumar.k
 
  Re: Differences between functions and stored procedures?
Answer
# 4
function does have update or delete statment.
 
Is This Answer Correct ?    2 Yes 0 No
Gautam
 
  Re: Differences between functions and stored procedures?
Answer
# 5
a stored procedure is like a subroutine. It is used to 
perform tasks within the database, whether it be to INSERT, 
UPDATE, DELETE, SELECT, send return values, send output 
parameters, send e-mail, call command line arguments, 
encapsulate business logic, enforce data integrity, or any 
combination thereof. Here is a fictitious example: 
 
CREATE PROCEDURE dbo.doStuff 
    @dt SMALLDATETIME 
AS 
BEGIN 
    SET NOCOUNT ON 
 
    DECLARE     @un SYSNAME, 
        @now SMALLDATETIME 
 
    SET @un = SUSER_SNAME() 
    SET @now = GETDATE() 
 
    BEGIN TRANSACTION 
 
    INSERT dbo.myLog 
    ( 
        ProcName, 
        UserName, 
        dt 
    ) 
    SELECT 
        'doStuff', 
        @un, 
        @now 
 
    DELETE dbo.myLog 
        WHERE dt < (@now-7) 
 
    UPDATE dbo.Users 
        SET LastActivity = @now 
        WHERE UserName = @un 
 
    COMMIT TRANSACTION 
 
    SELECT TOP 3 ProcName, dt 
        FROM MyLog 
        WHERE UserName = @un 
        ORDER BY dt DESC 
 
    DECLARE @subject VARCHAR(255) 
    SET @subject = @un + ' used the doStuff procedure.' 
 
    EXEC master..xp_smtp_sendmail 
        @from = 'foo@bar.com', 
        @to = 'bar@foo.com', 
        @server = 'mail.myserver.com', 
        @subject = @subject 
 
    DECLARE @cmd VARCHAR(255) 
    SET @cmd = 'del c:\users\'+@un+'\archive\*.log' 
    EXEC master..xp_cmdshell @cmd, NO_OUTPUT 
 
    RETURN 0 
END 
GO
 
Stored procedures accept parameters, and are the preferred 
method of both manipulating data and simply returning data. 
They are compiled when first run, and the query plans are 
stored and cached by SQL Server's optimizer, and those 
cached plans are swapped out depending on frequency of 
usage. Generally, a stored procedure will perform faster 
than an ad hoc query, but there are certain cases (e.g. 
when a bad plan is cached) that this is not the case. 

User-Defined Functions (UDFs) 

In general, UDFs can be a serious source of performance 
issues. Also, UDFs cannot be used for DML operations 
(INSERT/UPDATE/DELETE), cannot use non-deterministic 
functions ,cannot use dynamic SQL, and cannot have error-
handling (e.g. RAISERROR).
 
Is This Answer Correct ?    1 Yes 0 No
Rathi
 
  Re: Differences between functions and stored procedures?
Answer
# 6
FUnction use when you want to return any value only
but SP is best for all
 
Is This Answer Correct ?    1 Yes 0 No
Purushotam Bhardwaj
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
If you are working on a SQL database and if suddenly a developer changes the code and your queries results start giving errors,how will you check using a T-SQL query (on system tables) that what has changed in the database. Microsoft2
How many max. conditions can b written under the WHERE clause? Like select * from [tabnam] WHERE (cond1...or..cond2....or...cond3...and.....so on.....??? (upto how much extent))????? SAP-Labs2
Can we call SP inside a query? Wipro4
What is the difference between SSAS 2000 and SSAS 2005? APX1
How m-m relationships are implemented?  1
What is database normalization? Digicel5
how can i store resumes in database? HCL2
what is hash table Teledata2
from the table display the 2nd highest salary? and also the least 2nd salay?  6
what is a stored procedure and trigger?  1
What is the use of CASCADE CONSTRAINTS?  2
what is the main difference between after trigger and instead trigger.  1
In performance wise distinct is good or group by is good? eg:select name from emp group by name; select distinct name from emp; Infosys4
Following are some of the question related to below mentioned query? select e1.salary from employee3 e1 where 2= ( select count(distinct(e2.salary)) from employee3 e2 where e2.salary>=e1.salary ) 1) What the query returns? 2) How it works? - Detail explanation (what the sub query does, why it is (where 2=)....etc...Please?  3
How to delete particular value in the column of a table.Is it possible or not?if possible give it as in query.  4
one table has four field id,name,design,salary. i have to find maximum salary .  6
If there is failure during updation of certain rows, what will be the state?  1
What types of integrity are enforced by a foreign-key constraint  1
How to select Distinct columns from the table, table having 20 columns and i want all coulmns Wipro3
Explain fundamentals of Data ware housing & OLAP?  1
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com