dbTalk Databases Forums  

Truncate Table On Linked Server?

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Truncate Table On Linked Server? in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Neil
 
Posts: n/a

Default Truncate Table On Linked Server? - 05-15-2006 , 03:34 AM






Can one use Truncate Table on a linked server table? When I try it, I get a
message that only two prefixes are allowed. Here's what I'm using:

Truncate Table svrname.dbname.dbo.tablename



Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Truncate Table On Linked Server? - 05-15-2006 , 05:38 AM






Neil (nospam (AT) nospam (DOT) net) writes:
Quote:
Can one use Truncate Table on a linked server table? When I try it, I
get a message that only two prefixes are allowed. Here's what I'm
using:

Truncate Table svrname.dbname.dbo.tablename
I guess the error message answers your question.

There is also a good reason for this not being permitted. Truncate Table
is a special operation, that may not make sense on some other data source.
Remember that a linked server does not have to be SQL Server.

If you are on SQL 2005, you can say:

EXEC('TRUNCATE TABLE dbname.dbo.tablename') AT svrname

On earlier versions of SQL Server you are probably better off using DELETE
instead, although it could possible to do it with OPENQUERY.

--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #3  
Old   
Neil
 
Posts: n/a

Default Re: Truncate Table On Linked Server? - 05-15-2006 , 11:26 AM



Thanks.

"Erland Sommarskog" <esquel (AT) sommarskog (DOT) se> wrote

Quote:
Neil (nospam (AT) nospam (DOT) net) writes:
Can one use Truncate Table on a linked server table? When I try it, I
get a message that only two prefixes are allowed. Here's what I'm
using:

Truncate Table svrname.dbname.dbo.tablename

I guess the error message answers your question.

There is also a good reason for this not being permitted. Truncate Table
is a special operation, that may not make sense on some other data source.
Remember that a linked server does not have to be SQL Server.

If you are on SQL 2005, you can say:

EXEC('TRUNCATE TABLE dbname.dbo.tablename') AT svrname

On earlier versions of SQL Server you are probably better off using DELETE
instead, although it could possible to do it with OPENQUERY.

--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.