Truncate Table Across Linked Server

  • Good Afternoon All,
     
    Can anyone point me to where I can find documentation regarding Linked Servers and DDL?  I have a developer who is trying to truncate a table across a linked server.  I know that DDL statements are not supported, but want to have the documentation in hand when I make them change the code.  Any help is appreciated.
     
    Best Regards,
     
    Donna Robbins
  • Hello Donna,

    If you are using SQL 2000, then Books Online is the best resource to find information. Type "Linked Servers" and "Truncate Table" as search criteria.

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_1_server_4uuq.asp

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ta-tz_2hk5.asp

    Thanks and have a nice day!!!


    Lucky

  • It is not possible. You can select, insert, update and delete (with proper linkage and permissions of course) but if you attempt a truncate statement you will receive the following error:

    Server: Msg 117, Level 15, State 1, Line 1

    The object name 'mylinkedserver.tempdb.dbo.' contains more than the maximum number of prefixes. The maximum is 2.

    based on the following SQL statement:

    truncate table mylinkedserver.tempdb.dbo.t1

    RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."

  • However, you could switch to calling sp_executesql remotely, like so:

    execute mylinkedserver.tempdb.dbo.sp_executesql "TRUNCATE TABLE dbo.t1"

  • I stand corrected (there's always more than one way to do something in SQL). The one fly in ther ointment is that the user executing the command must be a dbo.

    RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."

  • Thanks everyone for your replies.  I knew DDL was not supported by linked servers, but could not find specifically that TRUNCATE is a DDL statement.  I found in Henderson's book, Guru's Guide to Transact-SQL in chapter 4, that TRUNCATE is definately DDL and can show it to the developer so they can't argue.  Since there are so few rows in the table, a delete will work fine.

    Best Regards,

  • Thank you. I learned something new today, that 'truncate' is a DDL statement ! I thought it might be DML

    RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."

  • thanks guys, this post really helped and i learned a nw thing.

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply