Finding Version Information and Details of All Databases in SQL Server

Hello everyone,

In this article, I will try to give information about the version information and details of all databases in SQL Server.

In SQL Server, in some cases, you may want to learn the version information and details of all databases.

You can easily do this using the code below.

SELECT @@servername AS 'Server Name',
       CONNECTIONPROPERTY('local_net_address') AS [IP Address],
       d.name AS [Database_Name],
       d.compatibility_level,
       @@version AS 'Version',
       CASE
           WHEN CONVERT(VARCHAR(128), SERVERPROPERTY('productversion')) LIKE '8%' THEN
               'SQL2000'
           WHEN CONVERT(VARCHAR(128), SERVERPROPERTY('productversion')) LIKE '9%' THEN
               'SQL2005'
           WHEN CONVERT(VARCHAR(128), SERVERPROPERTY('productversion')) LIKE '10.0%' THEN
               'SQL2008'
           WHEN CONVERT(VARCHAR(128), SERVERPROPERTY('productversion')) LIKE '10.5%' THEN
               'SQL2008 R2'
           WHEN CONVERT(VARCHAR(128), SERVERPROPERTY('productversion')) LIKE '11%' THEN
               'SQL2012'
           WHEN CONVERT(VARCHAR(128), SERVERPROPERTY('productversion')) LIKE '12%' THEN
               'SQL2014'
           WHEN CONVERT(VARCHAR(128), SERVERPROPERTY('productversion')) LIKE '13%' THEN
               'SQL2016'
           WHEN CONVERT(VARCHAR(128), SERVERPROPERTY('productversion')) LIKE '14%' THEN
               'SQL2017'
           WHEN CONVERT(VARCHAR(128), SERVERPROPERTY('productversion')) LIKE '15%' THEN
               'SQL2019'
           ELSE
               'unknown'
       END AS SQL_Server_Version,
       d.collation_name,
       (SUM(CAST(mf.size AS BIGINT)) * 8 / 1024) / 1024 AS Size_GBs
FROM sys.master_files mf
    INNER JOIN sys.databases d
        ON d.database_id = mf.database_id
WHERE d.database_id > 4 -- Skip system databases
GROUP BY d.name,
         d.compatibility_level,
         d.collation_name
ORDER BY d.name;

When you run the above code, you will see a result similar to the one below.

Finding Version Information and Details of All Databases in SQL Server

As you can see, we have learned the version information and details of all databases.

Good luck to everyone in business and life.

180 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!