Query sys.databases : sys.databases « System Tables Views « SQL Server / T-SQL Tutorial






3> USE master
4> GO
Changed database context to 'master'.
1>
2> DECLARE @DBName nvarchar(128)
3> DECLARE @TBLName nvarchar(128)
4> SET @DBName = N'Northwind'
5> SET @TBLName = N'Shippers'
6>
7>
8>
9> SELECT name
10> FROM sys.databases
11> WHERE name = @DBName
12> GO
name
--------------------------------------------------------------------------------------------------------------------------------

(0 rows affected)
1> SELECT name, object_id
2> FROM sys.tables
3> WHERE name = @TBLName
4> GO
Msg 137, Level 15, State 2, Server J\SQLEXPRESS, Line 3
Must declare the scalar variable "@TBLName".








27.2.sys.databases
27.2.1.Query sys.databases
27.2.2.SELECT name, is_auto_close_on FROM sys.databases
27.2.3.Query sys.databases for database name