-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathSQLGen_DBIndexPhysicalStats.sql
More file actions
34 lines (30 loc) · 2.1 KB
/
SQLGen_DBIndexPhysicalStats.sql
File metadata and controls
34 lines (30 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/************************************************************************************************
DESCRIPTION:
--------------------------------------------------------------------------------
Generate a script used to output the physical index fragmentation
The purpose of this script is to dynamically generate another SQL script based on
the content of the target server/database on which this script is executed.
The output of the execution of this script will be a seperate generated SQL script.
The generated script can be used to perform the actual function on your database/platform.
(1) Change result output to TEXT
(2) Execute the script on your target server/database
(3) Copy the result output as the new script to apply
HISTORY:
--------------------------------------------------------------------------------
Date: Developer: Description:
--------------------------------------------------------------------------------
* Rolf Tesmer Created
--------------------------------------------------------------------------------
NOTES:
--------------------------------------------------------------------------------
DISCLAIMER - https://mrfoxsql.wordpress.com/notes-and-disclaimers/
THIS SCRIPT/CODE ARE PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED.
LIMITED TESTING HAS BEEN PERFORMED ON THIS SCRIPT/CODE AND THEREFORE THE AUTHOR DOES NOT WARRANT
THAT ANY SCRIPT/CODE IS BUG OR ERROR-FREE. IT IS EXPECTED THAT ANY SCRIPT/CODE UNDERGO YOUR OWN
TESTING AND/OR VALIDATION BEFORE USAGE ON ANY CRITICAL SQL SERVER PLATFORM.
THIS SCRIPT MAY BE A COLLECTION OF MY OWN CODE COLLATED OVER MANY YEARS, OR OTHER CODE I HAVE
LOCATED ON THE WEB WITH AN UNKNOWN ORIGIN. WHERE CODE HAS BEEN IDENTIFIED IT WILL BE CITED.
************************************************************************************************/
SELECT 'use ['+[name]+'] select '''+[name]+''' as DBName, object_name(object_id) as ObjName, * from sys.dm_db_index_physical_stats ('+CAST([database_id] AS CHAR(2))+', NULL, NULL, NULL, NULL) order by 2, 5'
FROM [sys].[databases]
WHERE [database_id] > 4;