// system & session reference

SQL VERSION() and @@VERSION

Feature checks, bug reports and upgrade scripts all start with the server version. Every engine reports it from a query, in a different shape.

类别
System & session
Returns
text
In this category
6 of 13

语法

@@VERSION
version()
VERSION()
sqlite_version()
SELECT banner_full FROM v$version

Each block is a separate form. The support table and the examples show which engine takes which.

引擎支持

引擎Support备注
SQL Server Different name or syntax @@VERSION; SERVERPROPERTY('ProductVersion') for the number alone
PostgreSQL 是 version(); current_setting('server_version_num') for a comparable integer
MySQL 是 VERSION() or @@version
SQLite Different name or syntax sqlite_version()
Oracle Different name or syntax SELECT banner_full FROM v$version (needs access to the view)

示例

SQL Server

SELECT CAST(SERVERPROPERTY('ProductVersion') AS VARCHAR(20)) AS version,
       CAST(SERVERPROPERTY('ProductMajorVersion') AS VARCHAR(5)) AS major;  -- 17.0.4035.5, 17

PostgreSQL

SELECT version(), current_setting('server_version_num') AS num;  -- num is 180006 on 18.6

MySQL

SELECT VERSION();  -- 8.4.11

SQLite

SELECT sqlite_version();  -- 3.51.0

值得了解

  • Compare numbers, not banners. SERVERPROPERTY('ProductMajorVersion') returns 17 on SQL Server 2025, and server_version_num returns 180006 on PostgreSQL 18.6; comparing the strings '9.6' and '18.1' sorts them the wrong way.
  • SQLite's version is the library linked into the program, so two applications on one machine can report different versions for the same database file.
  • Recent Oracle Free images print 'Oracle AI Database 26ai Free Release 23.26.3.0.0': the marketing name changed, the release number still starts with 23.

Questions about VERSION()

Which major version numbers go with which SQL Server releases?

17 is SQL Server 2025, 16 is 2022, 15 is 2019, 14 is 2017 and 13 is 2016.

How should code test for a minimum version?

Read an integer and compare it: server_version_num >= 170000 on PostgreSQL, ProductMajorVersion >= 16 on SQL Server. On MySQL and SQLite split the dotted string into numbers first.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.