SQL Server 2008 sys.objects等效于sysobjects.uid

时间:2011-11-23 16:31:38

标签: sql sql-server sql-server-2005 sql-server-2008 sql-view

有谁知道如何从2005 + sysobjects(或其他)视图中获取等效的SQL Server 2000 uid sys.objects列?

我正在尝试转换此代码,因为我们正在删除所有sysobjects引用。

DECLARE GETOBJECTS CURSOR FOR 
SELECT NAME, UID FROM SYSOBJECTS
WHERE TYPE IN ('U','P')
    AND UID <> 1
    AND LOWER(RTRIM(NAME)) NOT LIKE 'PB%'

提前致谢,

凯文

2 个答案:

答案 0 :(得分:2)

UID 是指对象所有者的用户ID ...

在SQL 2005和SQl 2008中,您可以在

中找到它
sys.sysobjects 

字段名称 UID

Sys.sysobjects

UID = 1是dbo用户。

因此,要使用例程和表视图并过滤掉dbo,请尝试以下代码

select Routine_name as Name, specific_schema as user 
from INFORMATION_SCHEMA.ROUTINES
where specific_schema <> 'dbo'
UNION
select Table_name as Name, specific_schema as user 
from INFORMATION_SCHEMA.TABLES
where specific_schema <> 'dbo'

答案 1 :(得分:0)

要获取不属于dbo主体的所有对象,请执行以下操作:

select name, object_id
from sys.objects
where principal_id not in
(
    select principal_id
    from sys.database_principals
    where name = 'dbo'
)