-
Notifications
You must be signed in to change notification settings - Fork 16
/
- INFO - Various scripts to get information.sql
143 lines (108 loc) · 3.54 KB
/
- INFO - Various scripts to get information.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
Various queries for getting information out of the DBA Database
Connect to Server hosting DBA Database
Use
where IL.Inactive = 0
to only get active instances
*/
-- Generic infomration about Servers and locations and environments
Select IL.ServerName,
IL.InstanceName,
IL.Environment,
IL.location
FROM dbo.InstanceList IL
-- where IL.Environment = 'Prod'
-- Where IL.Location = 'Bolton'
-- Generic infromation about servers and clients
Select
DISTINCT C.ClientName,
IL.ServerName
FROM dbo.InstanceList IL
JOIN
dbo.ClientDatabaseLookup CDL
ON
CDL.InstanceID = IL.InstanceID
JOIN dbo.Clients C
ON c.ClientID = cdl.ClientID
WHERE C.ClientName <> 'DBA-Team' ---- AND C.ClientName = '' -- AND IL.ServerName = ''
group by C.ClientName ,ServerName
-- Generic SQL Instance Information Specifics can be picked from the SQLInfo table as required - The date checked value will show how up to date the data is
Select IL.ServerName,
IL.InstanceName,
IL.Environment,
IL.location,
SI.*
FROM dbo.InstanceList IL
JOIN info.SQLInfo SI
ON SI.instanceid = IL.InstanceID
--- Use the relevant where clause you require here
order by SI.ServerName
-- Generic Windows Information Specifics can be picked from the ServerOSInfo table as required - The date checked value will show how up to date the data is
Select
SOI.*
FROM info.serverosinfo SOI
-- Pick your required where clause here
-- Generic Database Information Specifics can be picked from the Databases table as required - The date checked value will show how up to date the data is
Select IL.ServerName,
IL.InstanceName,
IL.Environment,
IL.location,
D.*
FROM dbo.InstanceList IL
JOIN info.Databases D
ON D.InstanceID = IL.InstanceID
where D.Name = 'Name of Database 175'
-- pick your required where clause here
---- Job Detail INformation is in the AgentJobDetail table this holds infomration about every job that ran
Select IL.ServerName,
IL.InstanceName,
IL.Environment,
IL.location,
AJD.*
FROM dbo.InstanceList IL
JOIN info.AgentJobDetail AJD
ON AJD.InstanceID = IL.InstanceID
-- pick your required where clause here - Think about LastRuntime or outcome or server or job name
WHERE AJD.InstanceID
IN
(Select IL.InstanceID
FROM dbo.InstanceList IL
WHERE IL.Environment = 'Prod' ---- This clause is looking for Prod Environment Servers with Jobs that have Newport in the name
and AJD.JobName LIKE '%Index%')
and AJD.LastRunTime > DATEADD(day,-1,GETDATE()) --- That finished since yesterday
ORDER by AJD.LastRunTime desc
---- Job Server INformation is in the AgentJobServer table this holds a roll up of each days job records
Select IL.ServerName,
IL.InstanceName,
IL.Environment,
IL.location,
AJS.*
FROM dbo.InstanceList IL
JOIN info.AgentJobServer AJS
ON AJS.InstanceID = IL.InstanceID
-- pick your required where clause here - Think about LastRuntime or outcome or server or job name
WHERE AJS.InstanceID
IN
(Select IL.InstanceID
FROM dbo.InstanceList IL
WHERE IL.Environment = 'Prod' ---- This clause is looking for Prod Environment Servers in Bolton
and IL.Location = 'Bolton')
and AJS.Date > DATEADD(day,-1,GETDATE()) --- That were collected since yesterday
ORDER by IL.ServerName
-- Find the server a database is on
SELECT il.ServerName,
il.InstanceName,
il.Port,
d.Name,
il.Environment,
c.ClientName,
cdl.Notes
FROM info.Databases d
join dbo.InstanceList il
on il.InstanceID = d.InstanceID
join dbo.ClientDatabaseLookup cdl
on d.DatabaseID = cdl.DatabaseID
join dbo.clients c
on cdl.ClientID = c.ClientID
where d.name LIKE'%172%'
AND IL.InActive = 0