Troubleshooting Guide: SQL Server Error 361 – Column Mismatch in INSERT Statement
Why This Error Happens
Error 361 occurs when the number of columns specified in the target column list of an INSERT statement does not match the number of values provided in the VALUES clause or the source SELECT statement. This is typically caused by a manually written query with mismatched column-to-value counts, or a schema change (such as an added/dropped column) that was not reflected in an application’s data access layer or stored procedure. It can also surface after a table is altered while legacy INSERT statements in cached stored procedures or ORM-generated code still reference the old column structure.
Step-by-Step Resolution Guide
Step 1: Review the Exact INSERT Statement
- Open SQL Server Management Studio (SSMS) on Windows Server 2025 and locate the exact query from the error log at
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG. - Count the columns listed in the
INSERT INTO TableName (Col1, Col2, Col3)clause. - Count the values or selected columns in the corresponding
VALUES (...)orSELECTclause.
Step 2: Compare Against Current Table Schema
- Run
EXEC sp_help 'YourTableName';or queryINFORMATION_SCHEMA.COLUMNSto get the current, authoritative column list. - Check if a recent
ALTER TABLE(ADD/DROP COLUMN) was executed that changed the column count without updating dependent code. - Cross-reference this list against the INSERT statement identified in Step 1.
Step 3: Correct the Query or Stored Procedure
- Edit the INSERT statement to explicitly list matching column names equal to the number of supplied values.
- If using an ORM (Entity Framework, Dapper) or application layer, update the mapped entity/model class to reflect the new schema.
- If the issue originates in a stored procedure, use
ALTER PROCEDUREto correct the column list, then recompile usingEXEC sp_recompile 'YourProcedureName';.
Step 4: Clear Cached Execution Plans (If Applicable)
- If the schema was recently changed but the error persists intermittently, clear the plan cache for the specific object:
DBCC FREEPROCCACHE(OBJECT_ID('YourProcedureName'));. - This forces SQL Server to recompile the procedure against the current table definition.
Alternative or Verification Steps
- Verify the fix by re-executing the corrected INSERT statement or stored procedure in a test/staging environment on Windows 11 or Windows Server 2025 and confirming a successful row insertion with no Error 361.
- As an alternative, if the column list is long, use
INSERT INTO TableName DEFAULT VALUES(for fully defaulted tables) or explicitly omit identity/computed columns from both the column list and VALUES clause to avoid manual counting errors.