-
Notifications
You must be signed in to change notification settings - Fork 50
/
Find databases with default auto-growth values.sql
67 lines (62 loc) · 2.02 KB
/
Find databases with default auto-growth values.sql
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
-- Find databases with default auto-growth values
-- Part of the SQL Server DBA Toolbox at https://github.com/DavidSchanzer/Sql-Server-DBA-Toolbox
-- This script lists databases that have default auto-growth values, which is not desirable if they grow by a percentage
-- Drop temporary table if it exists
IF OBJECT_ID('tempdb..#info') IS NOT NULL
DROP TABLE #info;
-- Create table to house database file information
CREATE TABLE #info
(
databasename VARCHAR(128) NULL,
name VARCHAR(128) NULL,
fileid INT NULL,
filename VARCHAR(1000) NULL,
filegroup VARCHAR(128) NULL,
size VARCHAR(25) NULL,
maxsize VARCHAR(25) NULL,
growth VARCHAR(25) NULL,
usage VARCHAR(25) NULL
);
-- Get database file information for each database
SET NOCOUNT ON;
INSERT INTO #info
(
databasename,
filegroup,
fileid,
filename,
growth,
maxsize,
name,
size,
usage
)
EXEC dbo.sp_ineachdb @command = '
select ''?'',name, fileid, filename,
filegroup = filegroup_name(groupid),
''size'' = convert(nvarchar(15), convert (bigint, size) * 8) + N'' KB'',
''maxsize'' = (case maxsize when -1 then N''Unlimited''
else
convert(nvarchar(15), convert (bigint, maxsize) * 8) + N'' KB'' end),
''growth'' = (case status & 0x100000 when 0x100000 then
convert(nvarchar(15), growth) + N''%''
else
convert(nvarchar(15), convert (bigint, growth) * 8) + N'' KB'' end),
''usage'' = (case status & 0x40 when 0x40 then ''log only'' else ''data only'' end)
from sysfiles
';
-- Identify database files that use default auto-grow properties
SELECT databasename AS [Database Name],
name AS [Logical Name],
filename AS [Physical File Name],
growth AS [Auto-grow Setting]
FROM #info
WHERE (
usage = 'data only'
AND growth = '1024 KB'
)
OR (usage = 'log only' AND growth = '10%')
AND databasename NOT IN ( 'master', 'model', 'distribution', 'tempdb' )
ORDER BY databasename;
-- get rid of temp table
DROP TABLE #info;