Check current database name by using DB_NAME() : db_name « System Functions « SQL Server / T-SQL Tutorial






5> USE Northwind;
6> DECLARE @db AS NVARCHAR(258);
7> SET @db = QUOTENAME(N'pubs');
8> EXEC(N'USE ' + @db + ';');
9> SELECT DB_NAME();
10> GO








25.8.db_name
25.8.1.Check current database name by using DB_NAME()
25.8.2.if db_name() <> 'pubs'