Dealing with the Bits of a Binary Value in SQL Server


 

How you used to do it

For example, say you want to find all the read-write database using SQL Server 2022 system objects (I think this started back in 2005, in fact). You can write:

SELECT name FROM sys.databases WHERE is_read_only = 0 AND name IN (‘master’,’msdb’,’tempdb’);

This will return those three system databases (because they still will always be read-write.) Using the old sysdatabases object, there was just a status column.

SELECT name, status FROM sys.sysdatabases WHERE name IN (‘master’,’msdb’,’tempdb’);

On my computer, and most likely yours, the output from this query is:

name           status