SQL query skills two ways to query whether a table exists

Source: Internet
Author: User
SQL query skills two ways to query whether a table exists

Method 1: Determine whether a system object exists

Declare
@ Dbtablefilename varchar (100)

Set @ dbtablefilename = 'tx'

If objectproperty (object_id (@ dbtablefilename), 'isusertable') is not null
Print 'exists'
Else
Print 'not exists'

If object_id (@ dbtablefilename) is not null
Print 'exists'
Else
Print 'not exists'

If exists (select object_id (@ dbtablefilename ))
Print 'exists'
Else
Print 'not exists'

Method 2 query a table

Declare
@ Dbtablefilename varchar (100)

Set @ dbtablefilename = 'tx'

If exists (select 1
From sysobjects
Where name = @ dbtablefilename
And type = 'U ')
Print 'exists'
Else
Print 'not exists'

 

 

Organized from http://community.csdn.net/Expert/topic/5283/5283952.xml? Temp =. 733227.

Thank you.Loomman (yijian)Xiequanqin (New day, new start point !) Marco08) Bugchen888 (Bug) Caixia615 (* ^_^ *) then my neighbors R !. The hacker misses your ghost. (* ^_^ *)

 

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.