I've been learning Functions and Stored Procedure for quite a while but I don't know why and when I should use a function or a stored procedure. They look same to me, maybe because I am kinda newbie about that.
Can some one tell me why?
sqlsql serversql-functionstored-procedurestsql
I've been learning Functions and Stored Procedure for quite a while but I don't know why and when I should use a function or a stored procedure. They look same to me, maybe because I am kinda newbie about that.
Can some one tell me why?
Best Answer
Functions are computed values and cannot perform permanent environmental changes to
SQL Server
(i.e., noINSERT
orUPDATE
statements allowed).A function can be used inline in
SQL
statements if it returns a scalar value or can be joined upon if it returns a result set.A point worth noting from comments, which summarize the answer. Thanks to @Sean K Anderson: