Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 truncate a table on a linked server

Author  Topic 

herbau
Starting Member

3 Posts

Posted - 2012-10-17 : 16:21:56
I’m trying to truncate a table on a linked server. I’ve given myself all possible permissions on the linked server.
I can run:
SELECT * FROM linkedServer.import.dbo.SafetyStockTime
But when I run:
TRUNCATE TABLE linkedServer.import.dbo.SafetyStockTime
I get the error:
Cannot find the object "SafetyStockTime" because it does not exist or you do not have permissions.
So I know it exists, and I’ve assigned myself all possible permissions. Any help as to what I'm missing??
Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-10-17 : 16:48:11
You can't truncate a table over a linked server since truncate is DDL and not DML. You'll need to use delete instead or connect to the server directly rather than through the linked server.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-10-17 : 18:51:47
One option you can try is to create a stored procedure on the linked server that performs the TRUNCATE TABLE, then execute it via 4-part name:

EXEC linkedServer.import.dbo.TruncateProcedure

In SQL Server 2008 (not sure about previous versions), you can use the AT clause of the EXECUTE command:

EXEC ('TRUNCATE TABLE import.dbo.TruncateProcedure') AT linkedServer

See Books Online for more details under "EXECUTE".
Go to Top of Page
   

- Advertisement -