Troubleshooting Guide: SQL Server Error 3705
Why This Error Happens
Error 3705 occurs when a DROP statement is executed against an object using the wrong object-type keyword—for example, attempting to run DROP TABLE on an object that is actually a VIEW, or DROP PROCEDURE on an object that is actually a FUNCTION. SQL Server’s metadata engine validates the object type stored in sys.objects against the keyword used in the DROP statement, and a mismatch triggers this error before any schema modification occurs. This is typically caused by schema drift, incorrect deployment scripts, or confusion between similarly named objects created by different teams or automated CI/CD pipelines.
Step-by-Step Resolution Guide
Step 1: Identify the Actual Object Type
- Open SQL Server Management Studio (SSMS) or Azure Data Studio connected to the affected instance on Windows Server 2025 / Windows 11.
- Run the following query to confirm the real type of the object referenced in the error message:
SELECT name, type, type_desc
FROM sys.objects
WHERE name = 'YourObjectName';
- Cross-reference
type_desc(e.g.,VIEW,SQL_STORED_PROCEDURE,SQL_SCALAR_FUNCTION) with the keyword used in your originalDROPstatement.
Step 2: Correct the DROP Statement Syntax
- Replace the incorrect keyword with the one matching the
type_descoutput from Step 1. - Common corrections:
- Use
DROP VIEWinstead ofDROP TABLEfor views. - Use
DROP FUNCTIONinstead ofDROP PROCEDUREfor scalar or table-valued functions. - Use
DROP PROCEDUREinstead ofDROP FUNCTIONfor stored procedures. - Re-run the corrected statement in a new query window to confirm it executes without error.
Step 3: Audit and Fix Deployment/Migration Scripts
- Search your source-controlled
.sqldeployment scripts (e.g., in DevOps repos or SSDT projects) for the offendingDROPstatement using a text search tool likegrepor VS Code’s “Find in Files.” - Update the script to use the correct object-type keyword, and add a pre-check using
OBJECTPROPERTY()to future-proof the script:
IF OBJECTPROPERTY(OBJECT_ID('YourObjectName'), 'IsView') = 1
DROP VIEW YourObjectName;
- Commit and redeploy the corrected script through your standard CI/CD pipeline.
Step 4: Check for Naming Collisions Across Schemas
- Verify there isn’t a duplicate object name across different schemas (e.g.,
dbo.MyObjectvssales.MyObject) causing confusion in the script. - Run:
SELECT s.name AS SchemaName, o.name, o.type_desc
FROM sys.objects o
JOIN sys.schemas s ON o.schema_id = s.schema_id
WHERE o.name = 'YourObjectName';
- Fully qualify the object name with its schema in the corrected
DROPstatement to avoid ambiguity.
Alternative or Verification Steps
- Verify the fix by re-running the corrected
DROPstatement in a test/staging environment first; confirm no Error 3705 is returned and the object is removed fromsys.objects. - If the error persists, check for synonyms (
sys.synonyms) pointing to the object under a different name, asDROPstatements cannot target a synonym’s underlying object type directly—drop the synonym separately usingDROP SYNONYM.