patternsqlMajor
Is my SQL Server patched?
Viewed 0 times
sqlpatchedserver
Problem
How can I tell whether my SQL Server instances are patched? Is there native functionality that will identify whether there are patches available for my server? Heck, do I even have version data available to me?
Solution
To answer in reverse order
What version am I on?
There are two different queries that I use to identify my SQL Server level.
The first is @@version. The nice thing about this is that it brings back OS level information as well. The challenge with it is that it's a big dump of text and you have to parse that to find the relevant bits.
e.g.
My preference is to use
Is there native functionality to check for patches?
Nothing that I'm aware of. If the host OS has Windows Update service running and someone has specified "Include patches for other MS products" then you might get patches installed for SQL Server.
But, if you're a professional, you're probably not interested in waiting for a patch to be listed in WSUS or you'd like to validate that the patch works for your environment. That's going to involve reading knowledge base (KB) articles and testing.
How can I tell if my SQL Server instances are patched?
Lacking anything built into the product, I have been referencing sqlserverbuilds.blogspot.com. But there are plenty of other sites out there attempting to offer the same consolidated list of patches, such as:
I have taken the data from that blog and converted it to a View, dbo.PatchLevel. That view exposes all the patches. This view is truncated to only cover 2016 and 2014, otherwise I blow the character limit for answers.
```
CREATE VIEW dbo.PatchLevel
AS
-- data from http://sqlserverbuilds.blogspot.com
WITH SRC(Build,[File version],[KB / Description],[Release Date], SimpleVersion) AS
(
SELECT
CASE LEN(D.Build) - LEN(REPLACE(D.Build, '.', ''))
WHEN 3 THEN REPLACE(D.Build, '.00.', '.0.')
WHEN 2 THEN REPLACE(D.Build, '.00.', '.0.') + '.0'
END AS Build
, D.FileVersion
, D.KB
, CAST(REPLACE(D.ReleaseDate, ' *new', '') AS date) AS ReleaseDate
, CAST(LEFT(D.Build, 4) AS decimal(4,2))
FROM
(
VALUES
('13.00.500.53','2016.130.500.53','Microsoft SQL Server 2016 Community Technology Preview 2.3 (CTP2.3)','August 28, 2015 *new')
, ('13.00.407.1','2016.130.407.1','Microsoft SQL Server 2016 Community Technology Preview 2.2 (CTP2.2)','July 23, 2015')
, ('13.00.400.91','2016.130.400.91','Microsoft SQL Server 2016 Community Technology Preview 2.2 (CTP2.2) [withdrawn]','July 22, 2015')
, ('13.00.300.44','2016.130.300.444','Microsoft SQL Server 2016 Community Technology Preview 2.1 (CTP2.1)','June 24, 2015')
, ('13.00.200.172','2016.130.200.172','Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2)','May 27, 2015')
, ('12.00.4427','2014.120.4427.24','3094221 Cumulative update package 3 (CU3) for SQL Server 2014 Service Pack 1','October 21, 2015 *new')
, ('12.00.4422','2014.120.4422.0','3075950 Cumulative update package 2 (CU2) for SQL Server 2014 Service Pack 1','August 17, 2015')
, ('12.00.4416','2014.120.4416.0','3067839 Cumulative update package 1 (CU1) for SQL Server 2014 Service Pack 1','June 22, 2015')
, ('12.00.4213','2014.120.4213.0','MS15-058: Description of the nonsecurity update for SQL Server 2014 Service Pack 1 GDR: July 14, 2015','July 14, 2015')
, ('12.00.4100','2014.120.4100.1','SQL Server 2014 Service Pack 1 (SP1)','May 14, 2015')
, ('12.00.4050','2014.120.4050.0','SQL Server 2014 Service Pack 1 (SP1) [withdrawn]','April 15, 2015')
, ('12.00.2556','2014.120.2556.4','3094220 Cumulative update package 10 (CU10) for SQL Server 2014','October 20, 2015 *new')
, ('12.00.2553','2014.120.2553.0','3075949 Cumulative update package 9 (CU9) for SQL Server 2014','August 17, 2015')
, ('12.00.2548','2014.120.2548.0','MS15-058: Description of the security update for SQL Server 2014 QFE: July 14, 2015','July 14, 2015')
, ('12.00.2546','2014.120.2546.0','3067836 Cumulative update package 8 (CU8) for SQL Server 2014','June 22, 2015')
, ('12.00.2506','2014.120.2506.0','3063054 Update enables Premium Storage support for Data files on Azure Storage and resolves backup failures','May 19, 2015')
, ('12.00.2505','2014.120.2505.0','3052167 FIX: Error 1205 when you execute parallel query that contains outer join operators in SQL Server 2014','May 19, 2015')
, ('12.00.2504','2014.120.2504.0','2999809 FIX: Poor
What version am I on?
There are two different queries that I use to identify my SQL Server level.
The first is @@version. The nice thing about this is that it brings back OS level information as well. The challenge with it is that it's a big dump of text and you have to parse that to find the relevant bits.
e.g.
SELECT @@version;
/*
Microsoft SQL Server 2014 - 12.0.4416.0 (X64)
Jun 11 2015 19:18:41
Copyright (c) Microsoft Corporation
Developer Edition (64-bit) on Windows NT 6.3 (Build 9600: ) (Hypervisor)
*/My preference is to use
ServerProperties as I can individually identify the elements.SELECT
SERVERPROPERTY('productversion') AS ProductVersion
, SERVERPROPERTY ('productlevel') AS ProductLevel
, SERVERPROPERTY ('edition') AS Edition;
/*
ProductVersion ProductLevel Edition
12.0.4416.0 SP1 Developer Edition (64-bit)
*/Is there native functionality to check for patches?
Nothing that I'm aware of. If the host OS has Windows Update service running and someone has specified "Include patches for other MS products" then you might get patches installed for SQL Server.
But, if you're a professional, you're probably not interested in waiting for a patch to be listed in WSUS or you'd like to validate that the patch works for your environment. That's going to involve reading knowledge base (KB) articles and testing.
How can I tell if my SQL Server instances are patched?
Lacking anything built into the product, I have been referencing sqlserverbuilds.blogspot.com. But there are plenty of other sites out there attempting to offer the same consolidated list of patches, such as:
- http://sqlserverupdates.com/
- http://blogs.sqlsentry.com/category/sql-server-builds/
I have taken the data from that blog and converted it to a View, dbo.PatchLevel. That view exposes all the patches. This view is truncated to only cover 2016 and 2014, otherwise I blow the character limit for answers.
```
CREATE VIEW dbo.PatchLevel
AS
-- data from http://sqlserverbuilds.blogspot.com
WITH SRC(Build,[File version],[KB / Description],[Release Date], SimpleVersion) AS
(
SELECT
CASE LEN(D.Build) - LEN(REPLACE(D.Build, '.', ''))
WHEN 3 THEN REPLACE(D.Build, '.00.', '.0.')
WHEN 2 THEN REPLACE(D.Build, '.00.', '.0.') + '.0'
END AS Build
, D.FileVersion
, D.KB
, CAST(REPLACE(D.ReleaseDate, ' *new', '') AS date) AS ReleaseDate
, CAST(LEFT(D.Build, 4) AS decimal(4,2))
FROM
(
VALUES
('13.00.500.53','2016.130.500.53','Microsoft SQL Server 2016 Community Technology Preview 2.3 (CTP2.3)','August 28, 2015 *new')
, ('13.00.407.1','2016.130.407.1','Microsoft SQL Server 2016 Community Technology Preview 2.2 (CTP2.2)','July 23, 2015')
, ('13.00.400.91','2016.130.400.91','Microsoft SQL Server 2016 Community Technology Preview 2.2 (CTP2.2) [withdrawn]','July 22, 2015')
, ('13.00.300.44','2016.130.300.444','Microsoft SQL Server 2016 Community Technology Preview 2.1 (CTP2.1)','June 24, 2015')
, ('13.00.200.172','2016.130.200.172','Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2)','May 27, 2015')
, ('12.00.4427','2014.120.4427.24','3094221 Cumulative update package 3 (CU3) for SQL Server 2014 Service Pack 1','October 21, 2015 *new')
, ('12.00.4422','2014.120.4422.0','3075950 Cumulative update package 2 (CU2) for SQL Server 2014 Service Pack 1','August 17, 2015')
, ('12.00.4416','2014.120.4416.0','3067839 Cumulative update package 1 (CU1) for SQL Server 2014 Service Pack 1','June 22, 2015')
, ('12.00.4213','2014.120.4213.0','MS15-058: Description of the nonsecurity update for SQL Server 2014 Service Pack 1 GDR: July 14, 2015','July 14, 2015')
, ('12.00.4100','2014.120.4100.1','SQL Server 2014 Service Pack 1 (SP1)','May 14, 2015')
, ('12.00.4050','2014.120.4050.0','SQL Server 2014 Service Pack 1 (SP1) [withdrawn]','April 15, 2015')
, ('12.00.2556','2014.120.2556.4','3094220 Cumulative update package 10 (CU10) for SQL Server 2014','October 20, 2015 *new')
, ('12.00.2553','2014.120.2553.0','3075949 Cumulative update package 9 (CU9) for SQL Server 2014','August 17, 2015')
, ('12.00.2548','2014.120.2548.0','MS15-058: Description of the security update for SQL Server 2014 QFE: July 14, 2015','July 14, 2015')
, ('12.00.2546','2014.120.2546.0','3067836 Cumulative update package 8 (CU8) for SQL Server 2014','June 22, 2015')
, ('12.00.2506','2014.120.2506.0','3063054 Update enables Premium Storage support for Data files on Azure Storage and resolves backup failures','May 19, 2015')
, ('12.00.2505','2014.120.2505.0','3052167 FIX: Error 1205 when you execute parallel query that contains outer join operators in SQL Server 2014','May 19, 2015')
, ('12.00.2504','2014.120.2504.0','2999809 FIX: Poor
Code Snippets
SELECT @@version;
/*
Microsoft SQL Server 2014 - 12.0.4416.0 (X64)
Jun 11 2015 19:18:41
Copyright (c) Microsoft Corporation
Developer Edition (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)
*/SELECT
SERVERPROPERTY('productversion') AS ProductVersion
, SERVERPROPERTY ('productlevel') AS ProductLevel
, SERVERPROPERTY ('edition') AS Edition;
/*
ProductVersion ProductLevel Edition
12.0.4416.0 SP1 Developer Edition (64-bit)
*/CREATE VIEW dbo.PatchLevel
AS
-- data from http://sqlserverbuilds.blogspot.com
WITH SRC(Build,[File version],[KB / Description],[Release Date], SimpleVersion) AS
(
SELECT
CASE LEN(D.Build) - LEN(REPLACE(D.Build, '.', ''))
WHEN 3 THEN REPLACE(D.Build, '.00.', '.0.')
WHEN 2 THEN REPLACE(D.Build, '.00.', '.0.') + '.0'
END AS Build
, D.FileVersion
, D.KB
, CAST(REPLACE(D.ReleaseDate, ' *new', '') AS date) AS ReleaseDate
, CAST(LEFT(D.Build, 4) AS decimal(4,2))
FROM
(
VALUES
('13.00.500.53','2016.130.500.53','Microsoft SQL Server 2016 Community Technology Preview 2.3 (CTP2.3)','August 28, 2015 *new')
, ('13.00.407.1','2016.130.407.1','Microsoft SQL Server 2016 Community Technology Preview 2.2 (CTP2.2)','July 23, 2015')
, ('13.00.400.91','2016.130.400.91','Microsoft SQL Server 2016 Community Technology Preview 2.2 (CTP2.2) [withdrawn]','July 22, 2015')
, ('13.00.300.44','2016.130.300.444','Microsoft SQL Server 2016 Community Technology Preview 2.1 (CTP2.1)','June 24, 2015')
, ('13.00.200.172','2016.130.200.172','Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2)','May 27, 2015')
, ('12.00.4427','2014.120.4427.24','3094221 Cumulative update package 3 (CU3) for SQL Server 2014 Service Pack 1','October 21, 2015 *new')
, ('12.00.4422','2014.120.4422.0','3075950 Cumulative update package 2 (CU2) for SQL Server 2014 Service Pack 1','August 17, 2015')
, ('12.00.4416','2014.120.4416.0','3067839 Cumulative update package 1 (CU1) for SQL Server 2014 Service Pack 1','June 22, 2015')
, ('12.00.4213','2014.120.4213.0','MS15-058: Description of the nonsecurity update for SQL Server 2014 Service Pack 1 GDR: July 14, 2015','July 14, 2015')
, ('12.00.4100','2014.120.4100.1','SQL Server 2014 Service Pack 1 (SP1)','May 14, 2015')
, ('12.00.4050','2014.120.4050.0','SQL Server 2014 Service Pack 1 (SP1) [withdrawn]','April 15, 2015')
, ('12.00.2556','2014.120.2556.4','3094220 Cumulative update package 10 (CU10) for SQL Server 2014','October 20, 2015 *new')
, ('12.00.2553','2014.120.2553.0','3075949 Cumulative update package 9 (CU9) for SQL Server 2014','August 17, 2015')
, ('12.00.2548','2014.120.2548.0','MS15-058: Description of the security update for SQL Server 2014 QFE: July 14, 2015','July 14, 2015')
, ('12.00.2546','2014.120.2546.0','3067836 Cumulative update package 8 (CU8) for SQL Server 2014','June 22, 2015')
, ('12.00.2506','2014.120.2506.0','3063054 Update enables Premium Storage support for Data files on Azure Storage and resolves backup failures','May 19, 2015')
, ('12.00.2505','2014.120.2505.0','3052167 FIX: Error 1205 when you execute parallel query that contains outer join operators in SQL Server 2014','May 19, 2015')
, ('12.00.2504','2014.120.2504.0','2999809 FIX: Poor performance whCREATE VIEW dbo.MyPatchLevel
AS
WITH MostRecentBuild AS
(
SELECT
SRC.Build
, SRC.[Release Date]
, SRC.SimpleVersion
, SRC.[KB / Description]
FROM
dbo.PatchLevel AS SRC
WHERE
SRC.[Release Date] =
(
SELECT
MAX(SRCI.[Release Date])
FROM
dbo.PatchLevel AS SRCI
WHERE
SRCI.SimpleVersion = SRC.SimpleVersion
)
AND
SRC.Build =
(
SELECT
MAX(SRCI.Build)
FROM
dbo.PatchLevel AS SRCI
WHERE
SRCI.SimpleVersion = SRC.SimpleVersion
AND SRCI.[Release Date] = SRC.[Release Date]
)
)
, MyVersion AS
(
SELECT
SRC.Build
, SRC.[File version]
, MRB.[KB / Description]
, SRC.[Release Date]
, D.ProductVersion
, D.ProductLevel
, D.Edition
, D.Version
, SRC.SimpleVersion
, MRB.Build AS MostRecentBuild
, MRB.[Release Date] AS MostRecentReleaseDate
FROM
dbo.PatchLevel AS SRC
INNER JOIN
(
SELECT
SERVERPROPERTY('productversion') AS ProductVersion
, SERVERPROPERTY ('productlevel') AS ProductLevel
, SERVERPROPERTY ('edition') AS Edition
, @@VERSION AS Version
)D
ON D.ProductVersion = SRC.Build
INNER JOIN
MostRecentBuild AS MRB
ON MRB.SimpleVersion = SRC.SimpleVersion
)
SELECT
MV.ProductVersion AS CurrentVersion
, MV.MostRecentBuild
, MV.[Release Date]
, MV.MostRecentReleaseDate
, DATEDIFF(DAY, MV.[Release Date], MV.MostRecentReleaseDate) AS DaysSincePatchAvailable
, MV.[File version]
, MV.ProductLevel
, MV.[KB / Description] AS [Most Recent KB / Description]
, MV.Edition
, MV.Version
, MV.SimpleVersion
, CAST(SERVERPROPERTY('ComputerNamePhysicalNetBIOS') AS sysname) AS Server
, CAST(SERVERPROPERTY('InstanceName') AS sysname) AS Instance
, CAST(SERVERPROPERTY('ServerName') AS sysname) AS ServerName
FROM
MyVersion AS MV;
GOSELECT
MPL.CurrentVersion
, MPL.MostRecentBuild
, MPL.[Release Date]
, MPL.MostRecentReleaseDate
, MPL.DaysSincePatchAvailable
, MPL.[Most Recent KB / Description]
FROM
dbo.MyPatchLevel AS MPL;Context
StackExchange Database Administrators Q#115798, answer score: 26
Revisions (0)
No revisions yet.