SQL Server Error 405: How to Fix Remote Table Usage
In this article
SQL Server Error 405 occurs when you attempt to use a remote table—such as one accessed via a linked server—as the target of an INSERT, UPDATE, or DELETE operation. This is not allowed because SQL Server cannot guarantee transactional consistency or row-level locking across distributed systems. The fix requires restructuring your query to avoid direct modification of remote tables. Instead, you must pull data locally, modify it, and push changes back. This guide shows you how to resolve this error safely and efficiently.
What You'll Need
- Access to a SQL Server instance with permissions to query and modify local and linked servers
- Permissions to execute SELECT, INSERT, UPDATE, and DELETE statements on both local and remote tables
- A linked server configured and tested in SQL Server Management Studio (SSMS)
- SQL Server Management Studio (SSMS) version 18 or later, or Azure Data Studio
- Network connectivity to the remote server hosting the target table
Step-by-Step
- Verify the linked server connection by running a simple SELECT query against the remote table:
SELECT TOP 10 * FROM [LinkedServerName].[DatabaseName].[SchemaName].[TableName]. If this fails, troubleshoot the linked server configuration before proceeding. - Identify the exact operation causing the error—this is typically an INSERT, UPDATE, or DELETE statement that directly references the remote table. For example,
UPDATE [LinkedServer].[DB].[dbo].[Table] SET Column1 = 'NewValue' WHERE ID = 5will trigger Error 405. - Create a temporary local table to hold the data you intend to modify:
SELECT * INTO #TempTable FROM [LinkedServer].[DB].[dbo].[TableName] WHERE Condition. This copies only the rows you need into your local session. - Modify the data in the temporary table using standard SQL commands:
UPDATE #TempTable SET Column1 = 'NewValue' WHERE ID = 5. All changes occur locally and are fully supported. - Use a MERGE statement or a combination of INSERT and UPDATE to synchronize changes back to the remote table. For example:
MERGE [LinkedServer].[DB].[dbo].[TableName] AS Target USING #TempTable AS Source ON Target.ID = Source.ID WHEN MATCHED THEN UPDATE SET Target.Column1 = Source.Column1 WHEN NOT MATCHED THEN INSERT (ID, Column1) VALUES (Source.ID, Source.Column1); - If the remote table is large, limit the data pulled into the temp table using WHERE clauses to avoid memory overload. Always include a WHERE clause that filters to the smallest possible dataset.
- Test the entire workflow with a small subset of data first—ideally 5–10 rows—before running against production data.
- Drop the temporary table after the operation completes:
DROP TABLE #TempTable. This frees up memory and avoids clutter in tempdb. - Document the new workflow in your change log or database documentation, noting that remote tables can only be queried, never modified directly.
Common Mistakes
- Trying to use OPENQUERY() to wrap an UPDATE or DELETE statement—this still fails because the remote provider does not support direct modifications through distributed queries.
- Assuming that using a view over a linked server bypasses the restriction—views on remote tables are still subject to the same limitations.
- Copying entire large remote tables into temp tables without filtering, causing timeouts or tempdb space exhaustion.
- Forgetting to set up proper transaction handling around the MERGE or INSERT operations, leading to partial updates.
- Using the four-part naming convention ([Server].[DB].[Schema].[Table]) in a DELETE statement, thinking it will work—it will not, and will trigger Error 405.
Tips
- Use a stored procedure to encapsulate the entire workflow—this improves reusability and makes it easier to audit or troubleshoot.
- Consider using SQL Server Integration Services (SSIS) for recurring synchronization tasks between local and remote tables—it’s designed for this use case.
- Enable SET STATISTICS IO ON before running your queries to monitor how much data is being transferred and identify performance bottlenecks.
- If you frequently need to update remote data, ask your database administrator to set up replication or change data capture (CDC) instead of manual syncs.
- Always test in a non-production environment first. Remote table modifications can lock tables or cause replication delays if misconfigured.
- Use sp_helpserver to list all linked servers and verify their names match exactly in your queries—case sensitivity and trailing spaces can cause connection failures.
Troubleshooting
If the error persists after following the steps above, check the following:
- Ensure the linked server is configured to allow remote procedure calls (RPC) and RPC Out. Right-click the linked server in SSMS > Properties > Server Options, and verify both are set to True.
- Confirm the remote server’s provider supports update operations. Some providers, like OLE DB drivers for Oracle or Access, do not support write-backs even if configured correctly.
- Check SQL Server error logs for additional context—sometimes Error 405 is accompanied by a more specific underlying error, such as permission denial or network timeout.
- If using a firewall, ensure the port used by the linked server (commonly 1433 for SQL Server) is open in both directions.
- Test the connection using
EXEC sp_testlinkedserver 'LinkedServerName'. If it fails, the linked server is not properly configured. - If you're using a non-SQL Server remote system (e.g., MySQL or PostgreSQL), consider using a SQL Server Gateway or Azure Data Factory instead of linked servers for reliable bidirectional sync.
- If tempdb runs out of space during the operation, reduce the number of rows fetched by adding more restrictive filters or process data in batches.
Frequently Asked Questions
Can I use a view to update a remote table in SQL Server?
No. Views that reference remote tables are read-only for modification operations. SQL Server blocks INSERT, UPDATE, and DELETE on any view whose underlying table is on a linked server.
Why does SQL Server block direct updates to remote tables?
SQL Server cannot guarantee ACID compliance across distributed transactions without distributed transaction coordinators (DTC), and even then, performance and reliability suffer. Blocking direct modifications prevents inconsistent states and deadlocks.
Is there a way to enable direct updates to remote tables?
No. This is a deliberate architectural restriction, not a configuration option. Microsoft does not provide a registry key, sp_configure setting, or server option to bypass this limitation.
Can I use OPENROWSET instead of a linked server to avoid this error?
No. OPENROWSET still cannot be used as the target of an UPDATE or DELETE statement. It is only valid for SELECT operations and cannot be modified directly.
What if I need to update thousands of rows from a remote table?
Use batch processing: retrieve and update data in chunks of 1,000–5,000 rows at a time using a loop or cursor. This reduces memory pressure and prevents long-running transactions from blocking other users.
Does this error occur in Azure SQL Database?
No. Azure SQL Database does not support linked servers to external SQL Server instances. If you're seeing this error in Azure, you're likely using a managed instance with linked servers configured—same rules apply.