SHOW DATABASES Equivalent in SQL Server – sp_databases

There are several ways to show a list of databases in SQL Server. Probably the easiest way is to use the sp_databases stored procedure.

The sp_databases stored procedure is a kind of SQL Server equivalent to the SHOW DATABASES command that can be used with DBMSs such as MySQL and MariaDB. OK, maybe they aren’t strictly equivalents, but based on their ease of use, they could be viewed as such from a user’s perspective.

Continue reading

Add a Time Zone Offset to a datetime2 Value in SQL Server (T-SQL)

In SQL Server, the TODATETIMEOFFSET() function was specifically designed to return a datetimeoffset value from a datetime2 value.

Given the fact that the datetime2 data type doesn’t actually support time zone offsets, and datetimeoffset must contain the offset, the TODATETIMEOFFSET() function allows you to specify a time zone offset to use.

This article provides some examples to demonstrate.

Continue reading

Return the Current Workstation Name that’s Connected to SQL Server (T-SQL)

Occasionally you might find yourself in the situation where you need to get the name of the current workstation that’s connected to SQL Server.

For example, maybe you have a stored procedure that inserts data, and you want to record the name of the workstation that inserted the data.

In such cases, you can use the HOST_NAME() function.

This is not to be confused with getting the server name.

Continue reading