Why calling a user defined function need the owner name when calling a stored procedure doesn't ? Please help!
views:
62answers:
3Why calling a user defined function needs the owner name when calling a stored procedure doesn't ?
I assume you mean the schema name? Owner is the user that created it.
It distinguishes the function from a built-in function. "System" stored procedures and functions live in the master database (so it can be searched), while built-in functions (things like DATEADD
) reside in the database engine themselves.
I guess it's more difficult when you specify SELECT MyFunction()
for the database engine to work out whether you mean a function that lives in a database, or a built-in function.
After discussing with Andy above, I answer my own question here: Stored procedures are stored in the current database of the connection when created. In the mean time, functions are stored two locations: in the database engine (the scalar-value built-in ones) and in the current database of the connection (the user-defined ones). So the when calling the user-defined scalar-value functions, we need the schema name prefix to distinguish them vs the built-in ones. We don't need this prefix for the other types of functions and for the stored procedures.