SQL Server SHOW TABLES Equivalent

Every now and then I find myself typing SHOW TABLES in SQL Server, expecting to get a list of tables.

That would make perfect sense if I was using MySQL or MariaDB. But SQL Server/T-SQL doesn’t have a SHOW TABLES statement like MySQL or MariaDB, so it never works. And I keep forgetting. But fortunately, SQL Server does have alternatives.

Here are five options for getting a list of tables in SQL Server. These can be used whenever you’re trying to find that elusive SHOW TABLES statement in SQL Server.

Continue reading

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