给出表格的表格......
create table dbo.FilterIDXTest (
id int not null identity primary key clustered,
_bigint bigint,
_varchar10 varchar(10),
_varchar20 varchar(20),
_guid uniqueidentifier
);
go
create unique index uq_FilterIDXTest
on dbo.FilterIDXTest ( _varchar10, _varchar20 )
include ( _guid )
where _bigint is not null
and id > 5;
go
WHERE
...在什么(如果有的话)目录视图(或其他格式良好的参考对象)中可以找到并严格标识子句中的列名称?
sys.indexes
可以查看提醒我们的filter_definition
是([_bigint] IS NOT NULL AND [id]>(5))
。
sys.index_columns
可以查看以告诉我们ON
和INCLUDE
列,但仅列出原始CREATE INDEX
命令中 5 列中的 3 列。filter_predicate
此处未找到这些列。
我必须假设filter_predicate
在某个阶段严格检查了依赖关系,因为sp_rename 'dbo.FilterIDXTest._bigint', 'foo_bigint', 'column'
失败并出现错误...
Caution: Changing any part of an object name could break scripts and stored procedures.
Msg 5074, Level 16, State 1, Procedure sp_rename, Line 611
The index 'uq_FilterIDXTest' is dependent on column '_bigint'.
Msg 4922, Level 16, State 9, Procedure sp_rename, Line 611
RENAME COLUMN _bigint failed because one or more objects access this column.
...而且我无法让自己相信失败的唯一原因是因为在sys.indexes.filter_definition
.
作为参考,手头的任务是从许多未记录的遗留服务器中提取源代码。我为此目的使用 RedGate/一些其他付费助手应用程序的请求已被拒绝,因为“你可以从 UI 中编写出对象,对吧? ”。也许我过于严谨了,但我希望非常确信我正在签入源代码管理的索引是实际存在的索引。我正在sql server 2012上测试这个脚本,但它最终将在其上执行的目标服务器范围从2005 SP1到2008 R2 SP3。
我认为这些信息存储在
sys.sql_expression_dependencies
. 请参阅 MSDN 中的表格sys.sql_expression_dependencies
:另请注意,过滤索引在 2008 版中作为一项功能添加,而此系统视图在 2005 年不存在(感谢@Michael Eriksson 注意到这一点)。