AlterWorld AlterWorld - 1 year ago 74
SQL Question

Get schema name of the currently executing stored procedure

Is there a way to retrieve schema owner of a store procedure from within its implementation?

The stored procs are

. When the stored procedure gets executed, I need to retrieve name of the schema to perform some schema level tasks and also lookup objects (tables, columns, etc.) in that schema.

I tried
but it returns the default schema of the logged in user (which is
) not the schema owner of the stored procedure.

How do I get the schema of the executing stored procedure?

gbn gbn
Answer Source

Here you go...


Links to MSDN:

Returns the database schema name for schema-scoped objects

Returns the object identifier (ID) of the current Transact-SQL module.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download