Created
December 13, 2014 17:12
-
-
Save osya/1c9cb700537b8d92fa78 to your computer and use it in GitHub Desktop.
Запрос, чтобы узнать какие объекты базы в какой файловой группе находятся #SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT o .[name], o. [type], i.[name] , i .[index_id], f. [name] | |
FROM sys .indexes i | |
INNER JOIN sys. filegroups f | |
ON i .data_space_id = f .data_space_id | |
INNER JOIN sys. all_objects o | |
ON i .[object_id] = o .[object_id] | |
WHERE i .data_space_id = f .data_space_id | |
AND o .type = 'U' -- User Created Tables | |
ORDER BY f. [name] | |
--------------------------------------------------------------- | |
SELECT | |
ds.name AS filegroupname | |
, df .name AS 'FileName' | |
, physical_name AS 'PhysicalName' | |
, size /128 AS 'TotalSizeinMB' | |
, size /128.0 - CAST( FILEPROPERTY(df .name, 'SpaceUsed') AS int)/128.0 AS 'AvailableSpaceInMB' | |
, CAST (FILEPROPERTY( df.name , 'SpaceUsed' ) AS int)/ 128.0 AS 'ActualSpaceUsedInMB' | |
, ( CAST(FILEPROPERTY (df. name, 'SpaceUsed') AS int)/128.0 )/(size/ 128)*100. AS '%SpaceUsed' | |
FROM sys .database_files df LEFT OUTER JOIN sys .data_spaces ds | |
ON df .data_space_id = ds .data_space_id; | |
EXEC xp_fixeddrives | |
SELECT t .name AS TableName , | |
i.name AS IndexName, | |
p.rows AS Rows | |
FROM sys .filegroups fg ( nolock) JOIN sys .database_files df ( nolock) | |
ON fg .data_space_id = df .data_space_id JOIN sys .indexes i ( nolock) | |
ON df .data_space_id = i .data_space_id JOIN sys .TABLES t ( nolock) | |
ON i .object_id = t .object_id JOIN sys .partitions p ( nolock) | |
ON t .object_id = p .object_id AND i .index_id = p .index_id | |
WHERE fg .name = 'PRIMARY' AND t.type = 'U' | |
ORDER BY rows DESC | |
SELECT t .name AS TableName , | |
i.name AS IndexName, | |
p.rows AS Rows | |
FROM sys .filegroups fg ( nolock) JOIN sys .database_files df ( nolock) | |
ON fg .data_space_id = df .data_space_id JOIN sys .indexes i ( nolock) | |
ON df .data_space_id = i .data_space_id JOIN sys .TABLES t ( nolock) | |
ON i .object_id = t .object_id JOIN sys .partitions p ( nolock) | |
ON t .object_id = p .object_id AND i .index_id = p .index_id | |
WHERE fg .name = 'PRIMARY' AND t.type = 'U' AND i. index_id = 0 | |
ORDER BY rows DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment