In the actual work will be encountered through the SQL query database existence, some of the following statements can provide some help, the statement in this article is tested in the SQL08R2
1. Querying all databases of the current database server
SELECT * FROM master.dbo.sysdatabases
2, querying the database for existence
Select COUNT (*) from master.dbo.sysdatabases where name= ' database name '
3. Querying all user tables in a database
SELECT * from sysobjects where xtype= ' U '
' U ' stands for user table
C = CHECK Constraint D = default value or defaults constraint F = FOREIGN KEY constraint L = log FN = Scalar function
IF = Inline table function P = stored procedure PK = PRIMARY KEY constraint (type is K) RF = copy Filter stored procedure
S = system table TF = table function TR = trigger U = User Table UQ = UNIQUE constraint (type K)
V = View X = Extended stored Procedure
4 querying whether a table exists in a database
Select COUNT (*) from data name. dbo.sysobjects WHERE id = object_id (' database name. dbo. Table name ')
Resources:
Http://www.cnblogs.com/atree/p/SQL-Server-sysobjects.html
Http://www.cnblogs.com/puresoul/archive/2010/03/21/1691004.html
http://blog.csdn.net/fuyouche/article/details/8039197
Does SQL query database exist