difference

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pln
    New Member
    • Jan 2008
    • 1

    difference

    hi guys can u tell me the difference between funtion and a stored procedure??
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    by function I presume you mean user defined function (UDF)
    Its hard to define exactly so I will try in terms of how they are used

    Stored procedures
    may or may not take input parameters
    perform any number of separate operations via SQL
    that may or may not return a result to the caller.

    UDF
    always take input parameters
    perform any number of separate operations via SQL
    that may or may not return a result to the caller.

    UDF's are generally used to perform a calcutation using the input parameters and return a result but they can also return a table variable that holds the recordset of a query. When they return a table variable you can think of them as parameterised views

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      i think (read: am not sure) function's parameter are optional. functions may or may have parameter. in sql server, the difference between functions and stored-proc are almost blurred. but there are still major differences...a mong them,

      as of many other software and programming language, a function can not be called as a single statement call. a EXEC myFunction() is wrong. but this is valid in STORED PROC. to call a function, it has to be embedded in a statement set @myvar = myfunction()... .or select myfunction(), field1...from mytable...or could be if @myfunction() = somevalue.....

      it may also return a table which could act as a view. a view in difference with function, cannot accept parameter.

      most developer/programmer create stored proc to create module that will be executed in a regular basis. functions are usually created to be called within stored proc...these are "generally" speaking, this is not specific and not written in stone..

      that's it for now...i guess, it would depend on your requirement. your requirement will dictate whether you're to use function or stored proc.

      -- CK

      Comment

      • priyamv
        New Member
        • Jan 2008
        • 17

        #4
        The main difference between the function and stored procedure rather than stated above is that Stored procedures are precompiled.Whe n ever you execute a stored proc the compilation will not happen.They are precompiled and only run when they are executed.

        Comment

        • debasisdas
          Recognized Expert Expert
          • Dec 2006
          • 8119

          #5
          Originally posted by pln
          hi guys can u tell me the difference between funtion and a stored procedure??
          Please find the details here.

          Comment

          Working...