Skip to content
Microsoft SQL Server

SQL Server Error 1919

Column is of a type that is invalid for use as a key column in an index

Applies to: All supported SQL Server versions (2016 to 2025), Azure SQL Database, Azure SQL Managed Instance
Last technically reviewed 24 October 2026 on SQL Server 2025 (17.0.1145.4)
The full message
Msg 1919, Level 16, State 1, Line 1
Column 'title' in table 'dbo.Articles' is of a type that is invalid for use as a key column in an index.
Other forms of this message
PRIMARY KEY or UNIQUE constraint (the table name may appear without its schema; always followed by 1750)
Msg 1919, Level 16, State 1, Line 1
Column 'email' in table 'Customers' is of a type that is invalid for use as a key column in an index.
Msg 1750, Level 16, State 1, Line 1
Could not create constraint or index. See previous errors.
Different error for an xml column (reproduced on SQL Server 2025)
Msg 1977, Level 16, State 1, Line 1
Could not create index 'IX_b' on table 'dbo.Articles'. Only XML Index can be created on XML column 'body_xml'.
Error number
1919
Severity
16 (user-correctable error)
State
1
Product
Microsoft SQL Server Database Engine
Versions
All supported SQL Server versions (2016 to 2025), Azure SQL Database, Azure SQL Managed Instance
Last reviewed
24 October 2026

What it means

Error 1919 means you tried to use a large-value column (varchar(max), nvarchar(max), varbinary(max), text, ntext or image) as an index key, which SQL Server does not allow.

Index keys are stored in sorted order in every level of the index, so each key must fit within a fixed limit (900 bytes for a clustered index, 1,700 bytes for a nonclustered index). Large-value types can hold up to 2 GB per value, so SQL Server refuses them as key columns before it looks at any data, even when the table is empty. The message names the column and the table: check that column's data type.

The same rule applies to the hidden index behind a PRIMARY KEY or UNIQUE constraint, which is why a CREATE TABLE or ALTER TABLE ... ADD CONSTRAINT can fail with 1919 followed by 1750 ("Could not create constraint or index"). Large-value columns are still allowed in an index as included (non-key) columns, which is the basis of most fixes.

Common causes

  • A column declared as nvarchar(max) or varchar(max) by default (often by an ORM or a migration tool) and then used in CREATE INDEX.
  • A PRIMARY KEY or UNIQUE constraint on a (max) column, such as an e-mail address, URL or hash stored as varchar(max) or varbinary(max).
  • Legacy text, ntext or image columns in a key.
  • An index script copied from another database where the column had a shorter type.

Diagnose it

Read-only These queries only read metadata and dynamic management views. They do not change data, permissions or configuration, so they are safe to run first.

Which columns of the table cannot be index keys?

SELECT c.name AS column_name, t.name AS type_name, c.max_length
FROM sys.columns AS c
JOIN sys.types AS t ON t.user_type_id = c.user_type_id
WHERE c.object_id = OBJECT_ID(N'dbo.Articles')
  AND (c.max_length = -1 OR t.name IN (N'text', N'ntext', N'image', N'xml'))
ORDER BY c.column_id;
What to look for

Every column listed is a large-value type (max_length = -1) or a legacy type, and cannot be an ordinary index key.

How long are the values actually stored?

SELECT MAX(LEN(title)) AS longest_chars,
       MAX(DATALENGTH(title)) AS longest_bytes,
       COUNT(*) AS total_rows
FROM dbo.Articles;
What to look for

If the longest value is well below the key limit, a shorter type such as nvarchar(450) may be enough. If values can be long, use a hash or prefix column instead.

How to fix it

Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.

Shorten the column type if the data allows it

Changes schema

If diagnostic 2 shows the values are short, change the column to a fixed maximum length and then create the index. nvarchar(450) fits the 900-byte limit of a clustered key; up to nvarchar(850) fits the 1,700-byte nonclustered limit. Longer declared lengths are allowed with a warning, but inserting a key that exceeds the limit then fails.

Caution: ALTER COLUMN on a large table rewrites data and takes a schema lock; run it in a maintenance window, and check first that no stored value is longer than the new length.

ALTER TABLE dbo.Articles ALTER COLUMN title NVARCHAR(450) NULL;
CREATE INDEX IX_Articles_title ON dbo.Articles (title);

Index a hash of the value and include the full column

Changes schema

For long values you need to look up by equality (URLs, documents, file contents), add a persisted computed column with a hash and index that, carrying the full value as an included column. Queries filter on the hash and then compare the full value to rule out collisions.

ALTER TABLE dbo.Articles
    ADD title_hash AS CAST(HASHBYTES('SHA2_256', title) AS BINARY(32)) PERSISTED;
CREATE INDEX IX_Articles_title_hash ON dbo.Articles (title_hash) INCLUDE (title);

SELECT article_id
FROM dbo.Articles
WHERE title_hash = CAST(HASHBYTES('SHA2_256', N'Some title') AS BINARY(32))
  AND title = N'Some title';

Index a prefix of the value for range and LIKE searches

Changes schema

A computed column holding the first few hundred characters can be indexed; queries that filter or sort on title_prefix (for example title_prefix LIKE N'abc%') can then use it. Add the full-value condition to the query when values can share a prefix.

ALTER TABLE dbo.Articles
    ADD title_prefix AS CAST(LEFT(title, 400) AS NVARCHAR(400));
CREATE INDEX IX_Articles_title_prefix ON dbo.Articles (title_prefix);

Examples

CREATE INDEX on an nvarchar(max) column

SET NOCOUNT ON;
CREATE TABLE dbo.Articles (article_id INT PRIMARY KEY, title NVARCHAR(MAX), body NVARCHAR(MAX));

CREATE INDEX IX_Articles_title ON dbo.Articles (title);
Result
Msg 1919, Level 16, State 1, Line 4
Column 'title' in table 'dbo.Articles' is of a type that is invalid for use as a key column in an index.

Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.

PRIMARY KEY on a varchar(max) column

SET NOCOUNT ON;
CREATE TABLE dbo.Customers (
    email VARCHAR(MAX) NOT NULL PRIMARY KEY,
    name  VARCHAR(100)
);
Result
Msg 1919, Level 16, State 1, Line 2
Column 'email' in table 'Customers' is of a type that is invalid for use as a key column in an index.
Msg 1750, Level 16, State 1, Line 2
Could not create constraint or index. See previous errors.

Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.

UNIQUE constraint on a varbinary(max) column

SET NOCOUNT ON;
CREATE TABLE dbo.Documents (doc_id INT PRIMARY KEY, file_hash VARBINARY(MAX));

ALTER TABLE dbo.Documents ADD CONSTRAINT UQ_Documents_file_hash UNIQUE (file_hash);
Result
Msg 1919, Level 16, State 1, Line 4
Column 'file_hash' in table 'Documents' is of a type that is invalid for use as a key column in an index.
Msg 1750, Level 16, State 1, Line 4
Could not create constraint or index. See previous errors.

Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.

How to prevent it

Choose column lengths deliberately when you design a table: use (max) only for values that really can be very long, and give columns you will search, join or constrain a fixed maximum length. Check what your ORM generates, since many default strings to nvarchar(max).

Store fixed-size values such as hashes in fixed types (binary(32) for SHA-256), and replace legacy text, ntext and image columns with varchar(max), nvarchar(max) and varbinary(max). See SQL data types explained.

Common questions

Can a varchar(max) column be in an index at all?

Yes, as an included column (INCLUDE), not as a key column. It is then stored at the leaf level and can cover queries, but you cannot seek or sort on it.

Why do I get 1977 instead of 1919 for an xml column?

xml columns have their own rule: they can only be indexed with XML indexes (CREATE PRIMARY XML INDEX), so SQL Server reports 1977 instead.

Is nvarchar(1000) allowed as a key?

It can be created, with a warning that the key can exceed 1,700 bytes. Any insert or update that produces a key longer than the limit then fails, so prefer a length that fits.

Learn more on CodeWithSQL

Official documentation

Last technically reviewed 24 October 2026; examples and diagnostics run on SQL Server 2025 (17.0.1145.4). Message text checked against the engine's sys.messages catalogue.

Still stuck on a SQL Server error?

Browse the full SQL Server error library, or get hands-on help from an experienced SQL professional.