Check SQL Server Version
In SQL Server, you can check the version of the database engine using the @@VERSION
system variable or the SYS.SERVER_PROPERTIES
system view.
Syntax:
-- Using @@VERSION system variable
SELECT @@VERSION AS SQLServerVersion; -- Using SYS.SERVER_PROPERTIES system view
SELECT SERVERPROPERTY('ProductVersion') AS SQLServerVersion, SERVERPROPERTY('ProductLevel') AS ServicePackLevel, SERVERPROPERTY('Edition') AS Edition ;
Example 1: Check SQL Server Version using @@VERSION
Let's say we want to check the version of the SQL Server database engine.
Query:
SELECT @@VERSION AS SQLServerVersion;
Result:
SQLServerVersion |
---|
Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64) |
The result will display the version of the SQL Server database engine, including the major version, minor version, and build number.
Example 2: Check SQL Server Version using SYS.SERVER_PROPERTIES
Let's say we want to check the version of the SQL Server database engine, including the service pack level and edition.
Query:
SELECT SERVERPROPERTY('ProductVersion') AS SQLServerVersion, SERVERPROPERTY('ProductLevel') AS ServicePackLevel, SERVERPROPERTY('Edition') AS Edition ;
Result:
SQLServerVersion | ServicePackLevel | Edition |
---|---|---|
15.0.2000.5 | RTM | Enterprise Edition |
The result will display the version of the SQL Server database engine, including the service pack level and edition.
Example 3: Check SQL Server Version with Major and Minor Version
Let's say we want to check the major and minor version of the SQL Server database engine.
Query:
SELECT PARSENAME(CAST(SERVERPROPERTY('ProductVersion') AS VARCHAR(20)), 4) AS MajorVersion, PARSENAME(CAST(SERVERPROPERTY('ProductVersion') AS VARCHAR(20)), 3) AS MinorVersion ;
Result:
MajorVersion | MinorVersion |
---|---|
15 | 0 |
The result will display the major and minor version of the SQL Server database engine.