Stored Procedures or Functions are faster

  • Dear Friends,

    I wanted to know which are faster Functions/Procedures.

    With Reasons.

    regards

    shown

  • Depends how you use them... this is really where you make the choice. The server will still optimize the query equally in each object.

    Did you have a case scenario in mind?

  • Dear Remi,

    I don't have a specific scenario.

    This Question was asked to me for an interview.

    If possible will U be able to say some scenarios where Functions are faster than procedures or vice versa.

    regards

    shown

  • There's none really. Functions are meant to either return a table or a scalar value. Sp can do the same thing but they can't be used in a select statement. Also functions cannot insert/update/delete into permanent tables which is a big difference with procs.

    It's like asking which is faster, a screw driver or a hammer >> depends on the job . you'd be better off asking when it's better to use which objects or the difference I've mentioned (there are many others).

  • Dear Remi,

    Even I had the same answer as U told.

    But the interviewer made me think in a way one of them is faster than the other.

    regards

    shown

  • If you prove he's wrong then I think you get the job .

  • UDF performs a  row by row processing, so you might suffer a performce hit on big table...

  • If wants to use a table function as if it were a parametered view :

    Select col1, col2 from dbo.fnvwBigFastQuery(DateRange), not the other way around.

  • Nevermind, wrong thread .

  • Both are exactly the same speed just you use them differently

    create proc XX

    as

    select count(*) from sysobjects where type = 'U'

    go

    create function YY ()

    returns int

    as

    begin

    return(select count(*) from sysobjects where type = 'U')

    end

     

    exec xx

    or

    select dbo.yy()



    Bye
    Gabor

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply