Answer the question
In order to leave comments, you need to log in
How to fix the error of creating a unique index on NVARCHAR(MAX)?
I need to create table Faculties SQL query but row
Dean nvarchar(max) NOT NULL check(Dean != '') unique,
Msg 1919, Level 16, State 1, Line 7
Тип столбца "Dean" в таблице "Faculties" не позволяет выбрать его в качестве ключевого столбца индекса.
CREATE TABLE Faculties(
Id int primary key NOT NULL IDENTITY(1,1),
Dean nvarchar(max) NOT NULL check(Dean != '') unique,
[Name] nvarchar(100) NOT NULL check([Name] != '') unique
)
Answer the question
In order to leave comments, you need to log in
NVARCHAR(MAX)
not indexed.
CREATE TABLE Faculties(
ID INT PRIMARY KEY NOT NULL IDENTITY(1,1),
Dean NVARCHAR(MAX) NOT NULL CHECK(Dean<>''),
DeanIndex AS HASHBYTES('SHA',Dean) UNIQUE,
Name NVARCHAR(100) NOT NULL CHECK(Name<>'') UNIQUE
)
The length of nvarchar(max) is up to 2 31 -1 bytes.
The length of a non-clustered key is 1700 bytes.
It is logical that the field does not fit into the key.
Are you sure you have deans with such long names?
And for good, this field should contain the id of the dean in the table of employees.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question