Wednesday, June 4, 2014

Truncating table on Linked server

I was trying to truncate a table from a linked server with a command like:
Truncate table [Linked_Server].[Database].[Schema].[TableName], but I was getting an error stating: "The object name [Linked_Server].[Database].[Schema].[TableName] contains more than the maximum number of prefixes. The maximum is 2."

The fix for his was to run the sql through sp_executesql stored procedure on the Linked server:

EXEC [Linked_Server].[Database].sys.sp_executesql N'Truncate table dbo.MyTable'

No comments:

Post a Comment