Results 1 to 7 of 7

Thread: Table exists

  1. #1
    Join Date
    Sep 2003
    Posts
    212

    Unanswered: Table exists

    How do i check if to if a table exists in a database?

  2. #2
    Join Date
    Sep 2003
    Posts
    212
    declare @TableName sysname
    set @TableNAme = 'test'
    if OBJECTPROPERTY(OBJECT_ID(@TableName),'IsTable') = 1
    print 'yes'
    else
    print 'no'

    Found it on this forum. Thanks

  3. #3
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621
    select * from sysobjects where xtype='U' and name='yourtable'

  4. #4
    Join Date
    May 2003
    Location
    Rochester, NY
    Posts
    135

    sysobjects

    I've always selected from sysobjects using the 'type' column (e.g. select * from sysobjects where type ='U')

    What is the difference between these columns? (type vs. xtype)

    Thanks.

  5. #5
    Join Date
    Sep 2003
    Posts
    522
    xtype differentiates between pk and unique constraint, while type has the same value for both. type also identifies rule.

  6. #6
    Join Date
    May 2003
    Location
    Rochester, NY
    Posts
    135
    Yup, saw that in BOL, just wonderin' if there was an intended purpose for having both or is one to go away in a future release...

  7. #7
    Join Date
    Sep 2003
    Posts
    522
    i think xtype is to stay. type was passed on from 6.5 era.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •