When using SQL Server, you can use the sys.dm_os_host_info
system dynamic management view to return the operating system that SQL Server is running on.
This view includes a column called host_platform
which contains the type of operating system: Windows or Linux
Example 1 – Return Just the ‘host_platform’ Column
Here’s an example to demonstrate.
SELECT host_platform FROM sys.dm_os_host_info;
Result:
+-----------------+ | host_platform | |-----------------| | Linux | +-----------------+
Example 2 – Return All Columns
Of course, you can also return all columns. Here’s what that looks like on my system.
SELECT * FROM sys.dm_os_host_info;
Here it is using vertical output (so you don’t have to scroll sideways):
host_platform | Linux host_distribution | Ubuntu host_release | 16.04 host_service_pack_level | host_sku | NULL os_language_version | 0