When managing SQL Server instances, it's crucial to verify licensing details for compliance and capacity planning. Microsoft offers several licensing models (Per Core, Server+CAL, etc.) with different requirements.
The most direct way is querying the server properties:
SELECT SERVERPROPERTY('LicenseType') AS LicenseType,
SERVERPROPERTY('NumLicenses') AS LicenseCount,
SERVERPROPERTY('Edition') AS Edition,
SERVERPROPERTY('ProductLevel') AS Version;
This returns:
- LicenseType: DISABLED for Developer/Express, PER_SEAT for CAL-based, PER_PROCESSOR for core-based
- NumLicenses: Number of licenses (for PER_SEAT or PER_PROCESSOR)
For physical servers with core-based licensing, check:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.X\MSSQLServer\Setup
- ProductCode
- Edition
- LicenseType
For multiple servers, use this PowerShell snippet:
$servers = @('SQL01','SQL02')
$results = foreach ($server in $servers) {
try {
$conn = New-Object Microsoft.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=$server;Integrated Security=True"
$conn.Open()
$cmd = $conn.CreateCommand()
$cmd.CommandText = "SELECT @@SERVERNAME as ServerName, SERVERPROPERTY('LicenseType') as LicenseType"
$reader = $cmd.ExecuteReader()
while ($reader.Read()) {
[PSCustomObject]@{
Server = $reader["ServerName"]
License = $reader["LicenseType"]
}
}
} finally {
if ($conn.State -eq 'Open') { $conn.Close() }
}
}
$results | Export-Csv -Path "SQL_Licenses.csv"
Virtualized Environments: Remember core licensing follows the host's physical cores when using per-core licensing in VMs.
Developer Edition: Always shows as DISABLED license type since it's for development only.
Azure SQL: Licensing is managed through Azure portal and won't show in these queries.
- Cluster environments: Check each node individually
- SQL Server 2019+ may show additional license details in error logs
- For precise compliance, cross-reference with your Microsoft Volume Licensing portal
SQL Server offers several licensing options including:
- Per-core licensing (for enterprise environments)
- Server + CAL model (for smaller deployments)
- Special editions (Developer, Express, etc.)
The most reliable method is using T-SQL to query system views:
SELECT
SERVERPROPERTY('Edition') AS Edition,
SERVERPROPERTY('ProductLevel') AS ProductLevel,
SERVERPROPERTY('ProductVersion') AS ProductVersion,
SERVERPROPERTY('LicenseType') AS LicenseType,
SERVERPROPERTY('NumLicenses') AS NumLicenses
For automated checks across multiple servers:
$servers = 'SQL01','SQL02','SQL03'
$results = foreach ($server in $servers) {
[PSCustomObject]@{
ServerName = $server
Edition = Invoke-Sqlcmd -ServerInstance $server -Query "SELECT SERVERPROPERTY('Edition')" | Select-Object -ExpandProperty Column1
LicenseType = Invoke-Sqlcmd -ServerInstance $server -Query "SELECT SERVERPROPERTY('LicenseType')" | Select-Object -ExpandProperty Column1
}
}
$results | Format-Table -AutoSize
SQL Server stores some licensing information in the Windows Registry:
# For SQL Server 2016+
$regPath = 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\140\Tools\Setup'
# For SQL Server 2019
$regPath = 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\150\Tools\Setup'
Get-ItemProperty -Path $regPath | Select-Object Edition, Version
Important notes when checking licenses:
- Developer/Express editions will show different values than production licenses
- Virtualized environments may have different licensing requirements
- License compliance should be verified against your actual Microsoft agreement
For comprehensive license auditing:
CREATE PROCEDURE usp_GetSQLServerLicenseInfo
AS
BEGIN
SELECT
@@SERVERNAME AS ServerName,
SERVERPROPERTY('MachineName') AS MachineName,
SERVERPROPERTY('Edition') AS Edition,
SERVERPROPERTY('ProductVersion') AS ProductVersion,
SERVERPROPERTY('ProductLevel') AS ProductLevel,
SERVERPROPERTY('LicenseType') AS LicenseType,
SERVERPROPERTY('NumLicenses') AS NumLicenses,
cpu_count AS [LogicalCPUCount],
physical_memory_kb/1024 AS [PhysicalMemoryMB]
FROM sys.dm_os_sys_info
END