Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 517: Fix an Invalid Column Value

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

SQL Server error 517, "Adding a value to a '%ls' column caused overflow," means you tried to store a value that the column's data type cannot hold. The value itself isn't necessarily wrong; it simply exceeds the range (minimum to maximum) or the maximum length allowed for that column's type. The fix is to identify which column overflowed, then either change the value so it fits, or widen the column's data type to accommodate it. Error 517 is closely related to errors 8115 (arithmetic overflow converting a value) and 8152 (string or binary data would be truncated), but 517 specifically points at the target column in an INSERT, UPDATE or aggregate.

What You'll Need

  • Access to SQL Server Management Studio (SSMS), Azure Data Studio, or another client that can run T-SQL queries, with a login that has permission to read system catalog views and (if you need to alter tables) ALTER permission on the table.
  • The name of the table and column involved, or the full error message text, which normally includes the column name.
  • A way to test changes safely: a development or test copy of the database, or at minimum a transaction you can roll back before committing a structural change.
  • The business rules for the data: how large the values can realistically grow, which affects what new type you pick.

Step-by-Step

  1. Read the full error message. SSMS shows the message in the Messages tab, not just the red error dialog. A typical one reads: Msg 517, Level 16, State 2, Line 1, Adding a value to a 'datetime' column caused overflow. The quoted type and the column referenced in your INSERT or UPDATE tell you exactly where to look. If you ran an aggregate (such as SUM on an integer column), the overflow is in the calculated result, not in a stored column, and step 6 applies.
  2. Confirm the target column's data type. Query the catalog rather than guessing. In SSMS's Object Explorer you can expand the table and its Columns node, or run:
    SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'YourTable';
    This shows every column, its type and its size limit, so you can compare it against the value you were trying to insert.
  3. Compare the value to the type's range. Each SQL Server type has hard limits. TINYINT holds 0 to 255. SMALLINT holds -32,768 to 32,767. INT holds roughly -2.1 billion to 2.1 billion. SMALLDATETIME only accepts dates from 1900-01-01 through 2079-06-06, so a stored value outside that window trips error 517 even though DATETIME would accept it. DATETIME2 accepts a much wider date range than DATETIME. DECIMAL(p,s) allows only p total digits with s after the decimal point, so a number like 12345.678 placed in DECIMAL(5,2) overflows.
  4. Adjust the value if the column is correct. If the column's limit reflects a real business rule, fix the data instead of the schema. Cast, round, or truncate explicitly so the overflow becomes a deliberate decision: CAST(@Amount AS DECIMAL(5,2)) or ROUND(@Amount, 2). For dates, validate that the incoming date falls within the allowed range before inserting, and substitute a default (or reject the row) when it doesn't. Explicit casts also make the failure point obvious in your code rather than hiding inside an implicit conversion.
  5. Widen the column if the data is legitimately larger. When the column is genuinely too small, alter it inside a transaction so you can roll back if something unexpected happens:
    BEGIN TRANSACTION;
    ALTER TABLE dbo.YourTable ALTER COLUMN Amount DECIMAL(12,2) NOT NULL;
    -- verify, then COMMIT TRANSACTION; or ROLLBACK TRANSACTION;
    Choose the new type by looking at the largest values you actually expect, with headroom. Integers are cheap to widen (INT to BIGINT), and DATE/DATETIME2 are safer than SMALLDATETIME for modern data. Avoid shrinking a column: if existing rows won't fit the smaller type, the ALTER itself fails with an overflow error.
  6. Check aggregates and computed expressions. Error 517 is not limited to INSERT and UPDATE. A SUM() over an INT column can overflow when the total exceeds about 2.1 billion, because SUM of an INT column may be promoted to INT, not BIGINT. Cast the input first: SUM(CAST(Amount AS BIGINT)). The same applies to multiplication with * and to AVG on some types, so cast the operands to the larger type before the calculation.
  7. Re-run the failing statement and verify the result. After changing either the value or the column, run the original statement again and then select the affected row to confirm the stored value is exactly what you intended. Check that the update affected the number of rows you expected, and look for any silent truncation of decimals or dates you rounded.

Common Mistakes

The most common mistake is fixing the immediate value while ignoring every other code path that writes to the same column. If one stored procedure, one import job and one screen all insert into the column, all three need the same fix, otherwise the error returns from a different feature a few days later. Grep your codebase for the table and column name.

Another frequent error is conflating error 517 with error 8152 (string truncation) or 8115 (arithmetic overflow during conversion). They point to different layers: 517 blames the target column, 8115 often blames the declared variable, and 8152 blames a string length. Chasing the wrong one wastes time. Always read the exact message number and quoted type.

People also assume ALTER COLUMN always succeeds. It changes nullability and type for every existing row, so if any stored value wouldn't fit the new type, or a constraint, index, computed column or foreign key depends on the column, the ALTER fails and tells you why. Schedule it in a maintenance window for large tables, because changing a column type can force a scan and rebuild of dependent indexes.

Tips

Use SMALLDATETIME only where you are certain the date range is limited. DATE, DATETIME or DATETIME2 with an appropriate precision are safer defaults for new columns. For money-like data prefer DECIMAL over FLOAT, because DECIMAL has a defined precision and scale and behaves predictably in comparisons and sums.

When you import data from another system, validate it in a staging table with generous types (VARCHAR(MAX), BIGINT, DATETIME2) first, then convert to production types only after checking the maximum lengths and values with SELECT MAX(LEN(col)) and SELECT MIN(col), MAX(col). This catches overflow before it reaches a real table.

Set up tests that insert boundary values: the minimum and maximum for each type, a date on each edge of the range, and a value one step beyond each limit that should fail. Boundary tests catch type mismatches far more reliably than typical sample data.

Troubleshooting

Still getting 517 after widening the column? Check whether a variable, a parameter or a computed column feeds the insert. A DECIMAL(5,2) variable will round or fail long before it reaches a DECIMAL(12,2) column, and the error will quote the variable's type, not the column's.

Error appears during a bulk insert or SSIS load? Look for a format mismatch in the source file: a text date like 12/31/9999, a four-digit year stored as text, or an ID with decimals. Validate the source file's edge values, and in SSIS check the data type of the target column in the destination component, which sometimes differs from the table's declared type.

ALTER COLUMN is blocked. Read the accompanying error. A schema-bound dependency, a primary key or an index referencing the column, or a replication publication usually needs to be removed or handled before the type changes. Disable or drop the dependency where that's safe, or apply the change during a window, then recreate it.

Overflow occurs only some of the time. That points at a calculation, not storage. The same SUM on a different filter returns a larger total and crosses the type's ceiling. Cast inside the aggregate and the complaint disappears.

Frequently Asked Questions

What exactly does error 517 mean?

SQL Server is telling you that a value you tried to place in a column, or into a computed result, is outside the range that the column's data type accepts. The message names the type and often the column.

Is error 517 a data or a schema problem?

Either can be the cause. If the value is wrong or extreme, fix the data. If the column's type is too narrow for legitimate values, change the column's type. Decide using your business rules, not by trial and error.

Why does it happen with SMALLDATETIME but not DATETIME?

SMALLDATETIME only supports dates from 1900 through 2079. A value outside that window causes overflow. DATETIME and DATETIME2 accept a much wider range, so switching the type usually resolves it.

Can error 517 happen on SELECT?

Yes, when a calculation in the SELECT overflows: a SUM of an INT column that exceeds the INT maximum, or a multiplication that exceeds the declared type. Cast operands to BIGINT or DECIMAL before the calculation.

Will widening a column break my application?

Usually not, because wider types hold everything the old type held. But clients using typed parameters, linked servers or replication can behave unexpectedly, so test against a copy of the database before applying the change to production.

How do I find which column caused it in a large insert?

Split the insert into per-column tests, or compare the source values against INFORMATION_SCHEMA.COLUMNS limits. Insert the row into a staging table with loose types first, then query for values that exceed the target column's maximum.