Smart Systems for Home

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

SQL Server Error 511: Fix "Cannot Create a Row of Size

· 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

Error 511 means a single row in a table is too wide for SQL Server to store: it needs more bytes than SQL Server allows a row to hold, so the INSERT or UPDATE is rejected. The practical fix is to find the oversized table or row and shrink it — reduce the number of fixed-width and variable-width columns, change data types, or move rarely used wide columns into a separate table that you join when needed. In a typical modern layout the limit is 8,060 bytes per row on the classic row structure, and rows that overflow it need either narrower columns or the newer storage options.

Before you start, understand the exact message. SQL Server usually reports it as: "Cannot create a row of size 8094 which is greater than the allowable maximum row size of 8060." The two numbers matter. The number it names is the row size SQL Server tried to build; the 8060 is the row-size ceiling. The message sometimes arrives as an INSERT/UPDATE failure, and sometimes it comes from a CREATE TABLE or ALTER TABLE when the definition itself exceeds the limit. Knowing which statement triggered it tells you whether you are fixing data or fixing structure.

Also note that variable-length columns — varchar, nvarchar, varbinary, and the MAX variants — do not always count in full. When a row cannot fit in the in-row page space, SQL Server can move variable-length values off-row, into overflow pages or LOB storage, so the error is thrown when the in-row portion of the row still exceeds 8,060 bytes, or when the table is old-style text/image data. That is why a table can hold some large strings and still fail on a row with many wide columns.

What You'll Need

  • Access to the database with a login that can read schema metadata (at minimum the ability to query sys.columns, sys.indexes and sys.dm_db_index_physical_stats).
  • SQL Server Management Studio, Azure Data Studio, or another client that can run T-SQL. The steps below use T-SQL, which works the same in all current versions; tool menus differ slightly.
  • The exact text of the failing statement and, if the error names a row size, the table it came from.
  • A maintenance window or backup plan before any ALTER TABLE, because changing data types or dropping columns can affect application behaviour.

Step-by-Step

  1. Capture the failing statement and the table. Run the statement that produced error 511 and note the error text, especially the row size it reports. If the error comes from a stored procedure or trigger, the statement in the trace or the procedure body is the one to inspect. If it comes from a background process, use Extended Events or SQL Server Profiler to capture the exact SQL text.
  2. List the columns and their data types. Query the catalog for that table:
    SELECT c.name, t.name AS data_type, c.max_length, c.is_nullable FROM sys.columns c JOIN sys.types t ON c.user_type_id = t.user_type_id WHERE c.object_id = OBJECT_ID('dbo.YourTable') ORDER BY c.column_id;
    Sort mentally by max_length. Smallint is 2 bytes, int is 4, bigint is 8, datetime is 8, uniqueidentifier is 16, bit is 1. An nvarchar(1000) counts as 2,000 bytes, a varchar(1000) as 1,000. Add up the fixed-width columns first; those are charged in full to the in-row limit.
  3. Identify the usual culprits. Very wide nvarchar columns (nvarchar(4000) counts as 8,000 bytes by itself), varchar(8000) columns used as scratch space, UNIQUEIDENTIFIER or char(36) GUIDs stored alongside other wide columns, and many small columns that add up. A dozen moderate varchar columns can exceed 8,060 bytes just as easily as one giant one. Also check for a column defined as char(8000) rather than varchar — char pads every value to the full length, so it is always charged in full.
  4. Narrow the data types. Change oversized character columns to realistic sizes: nvarchar(255) rather than nvarchar(1000), or varchar rather than nvarchar where Unicode is genuinely not needed. Change int to smallint or tinyint only where the value range allows it. Never shrink a column below the longest existing value; check first with SELECT MAX(LEN(YourColumn)) FROM dbo.YourTable;
  5. Move wide, rarely queried columns to a separate table. This is the most reliable structural fix. Put the bulky text, notes, blobs or history columns in a companion table keyed on the same primary key, and join when you need them. Existing queries that select the wide column need updating, so plan the roll-out with the application team.
  6. Use LOB types deliberately. For genuinely large text, nvarchar(max), varchar(max) and varbinary(max) store values off-row. If the problem is a large string, changing nvarchar(4000) to nvarchar(max) can let values overflow out of the row. Be aware of the trade-offs: MAX types have their own indexing restrictions and performance profile, and they do not remove the 8,060-byte limit for fixed columns.
  7. Check indexes on the table. Indexed columns and included columns count toward the row-size calculation in a different way, and a wide nonclustered index can fail to create for the same reason. If a CREATE INDEX or REBUILD fails, look at the key and included column widths; remove unnecessary included columns or shrink the key columns.
  8. Apply the fix and verify. Make the changes on a copy in a test database, run the previously failing statement, and compare results. If the table is large, check fill factor and index fragmentation after a rebuild, then deploy to production in a maintenance window.

Common Mistakes

The most common mistake is to treat this as a storage or disk problem. Error 511 is about row width, not free disk space, so adding a data file, growing the log or shrinking the database does nothing.

Second is assuming an nvarchar(4000) column is "small" because the values in it are short. The definition drives the row-size calculation in statements like CREATE TABLE, and many nearly empty wide columns still add up.

Third is changing a column to a smaller type without checking existing data, which turns error 511 into a truncation error or silently cuts data. Always measure MAX(LEN()) first, and remember that LEN() ignores trailing spaces — verify padded values too.

Fourth is forgetting that datetime2, money, decimal as well as varchar and nvarchar all contribute; replacing ten datetime columns with a couple of small ones is often enough. Fifth is applying the change directly in production without testing the application queries, especially if you dropped or moved a column.

Tips

Design new tables so the sum of fixed columns plus the maximum of common variable values stays well under 8,060 bytes. Aim to leave headroom rather than packing to the limit.

Keep a schema documentation table or a script that computes the declared in-row width for each table, so you can spot wide tables before they bite. Re-run it when a developer adds columns.

Use SELECT * less in application code. Querying only the columns you need reduces both transfer and the chance of hitting row-size problems in views and joins that combine column sets.

If you inherit a legacy table with too many columns, consider vertical partitioning over time — split stable, queried columns from bulky, rarely used ones. This also makes maintenance operations on the hot columns cheaper.

Troubleshooting

If the error appears only on INSERT for some rows and not others, the problem is the actual data width in those rows, and it may be caused by the outer SELECT or VALUES list supplying wider values than expected — for example, a computed string. Trace the values with a SELECT of LEN() and DATALENGTH() before inserting.

If CREATE TABLE fails with 511, the definition exceeds the limit; reduce the declared sizes until it succeeds. If ALTER TABLE ADD fails, the new column pushes the widest existing row over the limit; add it to a side table or reduce another column.

If the error survives a data-type change, remember indexes and computed columns. A persisted computed column is stored in the row and counts. Remove or recalculate it if it is wide.

If the error appears only in a view, the view joins multiple tables and the combined row is too wide; select fewer columns or split the view.

Frequently Asked Questions

Is 8,060 bytes the absolute limit?

It is the classic in-row limit for the standard row structure. Variable-length data can partly go off-row with overflow storage, and MAX types store off-row entirely, but fixed-width columns and the in-row portion of variable columns must fit. Large object and columnstore storage have their own rules.

Will changing nvarchar to varchar fix it?

It halves the byte cost of those columns, which often is enough, but only do it if the application genuinely does not need Unicode characters. Data outside the code page can be lost.

Can an index cause error 511?

Yes. Creating or rebuilding an index that includes many wide columns can exceed the row-size limit, even when the table itself is fine.

Does SQL Server compress away the problem?

Row and page compression can reduce physical size, but they do not change the logical column definitions or make every row fit; they are not a reliable fix for a structurally too-wide table.

Why did it work before and fail now?

Usually a schema change added a column, or data grew so the variable values no longer fit. Compare the current column list with the schema at the time it worked.