我遵循一个在线示例,说明如何使用这样的脚本创建文件表
CREATE TABLE [dbo].[Users] AS FILETABLE ON [PRIMARY] FILESTREAM_ON [FGFS]
GO
当我像这样运行查询时
SELECT * FROM sys.key_constraints WHERE parent_object_id=xxxxx
SELECT * FROM sys.index_columns WHERE object_id=yyyyy
第一个给我3个键(1PK + 2UQs)
我怎么知道哪个是
是FILETABLE_PRIMARY_KEY_CONSTRAINT_NAME
还是FILETABLE_STREAMID_UNIQUE_CONSTRAINT_NAME
还是FILETABLE_FULLPATH_UNIQUE_CONSTRAINT_NAME
?
答案 0 :(得分:1)
就像任何表一样,您可以使用sp_help
快速获取索引详细信息:
EXEC sp_help N'dbo.Users';
索引详细信息如下:
+-----------------------------+------------------------------------------------------+---------------------------+
| index_name | index_description | index_keys |
+-----------------------------+------------------------------------------------------+---------------------------+
| PK__Users__5A5B77D52FBBA93E | nonclustered, unique, primary key located on PRIMARY | path_locator |
| UQ__Users__9DD95BAF3C1BB377 | nonclustered, unique, unique key located on PRIMARY | stream_id |
| UQ__Users__A236CBB35BE6FD63 | nonclustered, unique, unique key located on PRIMARY | parent_path_locator, name |
+-----------------------------+------------------------------------------------------+---------------------------+
以下查询将使用目录视图返回约束名称和列名称:
SELECT kc.name AS constraint_name, c.name AS column_name
FROM sys.filetables AS t
JOIN sys.key_constraints AS kc ON kc.parent_object_id = t.object_id
JOIN sys.index_columns AS ic ON ic.object_id = kc.parent_object_id AND ic.index_id = kc.unique_index_id
JOIN sys.columns AS c ON c.object_id = ic.object_id AND c.column_id = ic.column_id
WHERE t.object_id = OBJECT_ID(N'dbo.Users', 'U')
ORDER BY kc.name, ic.key_ordinal;