What is the ideal way to check if a database exists on a SQL Server using TSQL? It seems multiple approaches to implement this.
Actually it's best to use:
IF DB_ID('dms') IS NOT NULL --code mine :) print 'db exists'
See https://docs.microsoft.com/en-us/sql/t-sql/functions/db-id-transact-sql and note that this does not make sense with the Azure SQL Database.
2.1m questions
2.1m answers
60 comments
57.0k users