Is there a way to retrieve schema owner of a store procedure from within its implementation?
有没有办法从其实现中检索商店过程的架构所有者?
The stored procs are World.Perform_Task
and Universe.Perform_Task
. 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.
存储的过程是World.Perform_Task和Universe.Perform_Task。当存储过程执行时,我需要检索模式的名称以执行某些模式级别任务,并查找该模式中的对象(表,列等)。
I tried Schema_Name()
but it returns the default schema of the logged in user (which is dbo
) not the schema owner of the stored procedure.
我尝试了Schema_Name(),但它返回登录用户(即dbo)的默认架构,而不是存储过程的架构所有者。
How do I get the schema of the executing stored procedure?
如何获取执行存储过程的模式?
1 个解决方案
#1
15
Here you go...
干得好...
OBJECT_SCHEMA_NAME(@@PROCID)
Links to MSDN:
MSDN的链接:
- OBJECT_SCHEMA_NAME
- OBJECT_SCHEMA_NAME
Returns the database schema name for schema-scoped objects
返回架构范围对象的数据库架构名称
- @@PROCID
- @@ PROCID
Returns the object identifier (ID) of the current Transact-SQL module.
返回当前Transact-SQL模块的对象标识符(ID)。
#1
15
Here you go...
干得好...
OBJECT_SCHEMA_NAME(@@PROCID)
Links to MSDN:
MSDN的链接:
- OBJECT_SCHEMA_NAME
- OBJECT_SCHEMA_NAME
Returns the database schema name for schema-scoped objects
返回架构范围对象的数据库架构名称
- @@PROCID
- @@ PROCID
Returns the object identifier (ID) of the current Transact-SQL module.
返回当前Transact-SQL模块的对象标识符(ID)。