In this post, I will show you how to create SCCM collection for SQL Server. You can group all the Windows servers that are running SQL Server into a device collection in Configuration Manager.

Each Configuration Manager site requires a supported SQL Server version and configuration to host the site database. A dedicated SQL server device collection can help you understand what versions of SQL are currently installed in your environment and help you manage them using SCCM. You can deploy SQL updates to this collection, perform maintenance tasks and much more.

SCCM includes built-in collections, but you may need to create additional collections based on your needs. A WQL query can help you determine the SQL server versions that are installed in your setup. You can modify this query by specifying the SQL version that you’re looking for and creating a device collection.

Install and Update Third Party Applications with Patch My PC
Install and Update Third Party Applications with Patch My PC

Also Read: Add Multiple Devices to SCCM collection using PowerShell

Prerequisites

  • The Windows server that hosts the SQL Server should be installed with a client agent.
  • The client agent should be updated to the latest version. You can use the automatic client upgrade method to update all clients to the latest version.

WQL Query for Microsoft SQL Server

Use this WQL query to find all the Microsoft SQL Server versions running in your environment.

select * from  SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceID = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM.Roles like "%SQLServer%"

WQL Query for Microsoft SQL Server 2022

Use this WQL query to find all the SQL Server 2022 in your environment.

select SMS_R_SYSTEM.ResourceID, SMS_R_SYSTEM.ResourceType, SMS_R_SYSTEM.Name, SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup, SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.ResourceId in (select distinct SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID from SMS_G_System_ADD_REMOVE_PROGRAMS where SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName = 'Microsoft SQL Server 2022')

WQL Query for Microsoft SQL Server 2019

Use this WQL query to find all the SQL Server 2019 in your environment.

select SMS_R_SYSTEM.ResourceID, SMS_R_SYSTEM.ResourceType, SMS_R_SYSTEM.Name, SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup, SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.ResourceId in (select distinct SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID from SMS_G_System_ADD_REMOVE_PROGRAMS where SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName = 'Microsoft SQL Server 2019')

WQL Query for Microsoft SQL Server 2017

Use this WQL query to find all the SQL Server 2017 in your environment.

select SMS_R_SYSTEM.ResourceID, SMS_R_SYSTEM.ResourceType, SMS_R_SYSTEM.Name, SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup, SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.ResourceId in (select distinct SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID from SMS_G_System_ADD_REMOVE_PROGRAMS where SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName = 'Microsoft SQL Server 2017')

Create SCCM Collection for SQL Server

Let’s create a device collection in SCCM that groups all your SQL servers present in the setup. Open the Configuration Manager console and click Assets and Compliance > Device Collections. On the top ribbon, select Create Device Collection.

Create SCCM Collection for SQL Server
Create SCCM Collection for SQL Server

Enter the device collection name, choose the limiting collection and click Next.

Create SCCM Collection for SQL Server
Create SCCM Collection for SQL Server

On the Membership Rules window, click Add Rule and from the drop-down, select Query Rule.

Select Add Query Rule
Select Add Query Rule

In the Query Rule Properties box, enter the query name and click Edit Query Statement. In the Query statement properties window, select the Criteria tab. Click Show query language and enter the below WQL query to create a Microsoft SQL Server device collection.

select SMS_R_SYSTEM.ResourceID, SMS_R_SYSTEM.ResourceType, SMS_R_SYSTEM.Name, SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup, SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.ResourceId in (select distinct SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID from SMS_G_System_ADD_REMOVE_PROGRAMS where SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName = '%Microsoft SQL Server%')
Specify WQL query for SQL Server
Specify WQL query for SQL Server

Click OK three times and continue with the Create Device Collection Wizard. The Membership Rules page now displays the rule name and the query information that you just specified. Click Next.

Create SCCM Collection for SQL Server
Create SCCM Collection for SQL Server

Review the changes on the Summary page. Complete the remaining steps and close the wizard.

Create SCCM Collection for SQL Server
Create SCCM Collection for SQL Server

After a few minutes, in the SCCM console, check the member count of the SQL Server device collection. The collection should group all the SQL servers in your hierarchy. If the device collection is not updating, review the colleval.log which records details about when collections are created, changed, and deleted by the collection evaluator.

Collection Creation Guides

Still Need Help?

If you need further assistance on the above article or want to discuss other technical issues, check out some of these options.

Prajwal Desai

Prajwal Desai is a technology expert and 10 time Dual Microsoft MVP (Most Valuable Professional) with a focus on Microsoft Intune, SCCM, Windows 365, Enterprise Mobility, and Windows. He is a renowned author, speaker, & community leader, known for sharing his expertise & knowledge through his blog, YouTube, conferences, webinars etc.