Does SQL query database exist

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.