开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 9183|回复: 0

查询分区情况多表

[复制链接]

0

精华

597

贡献

110

赞扬

赞助者组

Rank: 14Rank: 14Rank: 14Rank: 14

帖子
18
软币
336
在线时间
19 小时
注册时间
2017-8-3
发表于 2020-10-16 09:11:05 | 显示全部楼层 |阅读模式
-------多个表用逗号拼接表名
DECLARE @tabname NVARCHAR(MAX) = '表1,表2,表3'

SELECT tv.value AS '表名',t.name AS '分区索引',tc.name AS 分区字段,t1.name AS '分区方案',t2.name AS '分区函数',t3.value AS '分区界限',t5.name AS '文件组',t6.name AS '文件',t6.physical_name AS '文件位置'
FROM sys.indexes t
INNER JOIN (SELECT OBJECT_ID(value) AS objectid,value FROM dbo.Split(@tabname,',')) tv ON tv.objectid = t.object_id
OUTER APPLY(SELECT ISNULL((SELECT STUFF((SELECT ','+ name FROM (SELECT CAST(name AS NVARCHAR(256)) AS name FROM sys.columns a  INNER JOIN sys.index_columns tci ON a.column_id = tci.column_id AND a.object_id = tci.object_id
WHERE tci.index_id = t.index_id AND tci.object_id = t.object_id )ty FOR XML PATH('')),1,1,'')),'') AS name) tc
LEFT JOIN sys.partition_schemes t1 ON t1.data_space_id = t.data_space_id
LEFT JOIN sys.partition_functions t2 ON t2.function_id = t1.function_id
LEFT JOIN sys.partition_range_values t3 ON t3.function_id = t1.function_id
LEFT JOIN sys.destination_data_spaces t4 ON t4.partition_scheme_id = t1.data_space_id AND t4.destination_id = t3.boundary_id
LEFT JOIN SYS.filegroups t5 ON t5.data_space_id = t4.data_space_id
LEFT JOIN SYS.database_files t6 ON t6.data_space_id = t4.data_space_id
WHERE t.data_space_id > 1


回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-12-22 02:57

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表