Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2009
    Posts
    47

    Question Unanswered: Condition check for Table exist

    How can I use the following Query using Dynamic Sql.The purpose of using Dynamic SQL is the table is on another server.

    Generally when I use Dynamic SQL against select query I use
    EXEC('SELECT * FROM '+@SERVERNAME+'.'+@LOCALDBNAME+'.DBO.'+'ÇUSTOMERS' )

    Here goes my Query

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MyTable]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[MyTable]
    GO

  2. #2
    Join Date
    Dec 2008
    Posts
    135
    If Object_Id('databasename..Customers') Is Not Null
    Drop Table Customers

  3. #3
    Join Date
    Dec 2008
    Posts
    135
    if exists(select * from information_schema.tables where table_name = 'customers' and table_catalog = @databasename)
    drop table customers

  4. #4
    Join Date
    Mar 2009
    Posts
    47
    And wht about if its on another server i.e Remote server where can I specify that

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Linked server?
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

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