Verifying the existence of the default database. : sysdatabases « System Tables Views « SQL Server / T-SQL Tutorial






14>
15>     CREATE PROC pr_verifydb (@dbname varchar(30))
16>     AS
17>     DECLARE @dbid int
18>     SELECT @dbid = dbid from sysdatabases
19>          where name = @dbname
20>     IF @@rowcount = 0
21>          RETURN 50
22>     RETURN 0 -- Everything is perfect!!!
23>     GO
1>
2>








27.27.sysdatabases
27.27.1.sysdatabases contains a row for every system and user-defined database on the SQL Server system.
27.27.2.Verifying the existence of the default database.