我有一个表格,其中有一个计算的VARCHAR列,最多包含106个字符:
CREATE TABLE report (
report_id INT IDENTITY(1, 1) NOT NULL,
name VARCHAR(100) COLLATE Modern_Spanish_CI_AI NOT NULL,
city_id VARCHAR(6) COLLATE Modern_Spanish_CI_AI,
unique_name AS
CASE
WHEN city_id IS NULL
THEN name
ELSE name + REPLICATE(' ', 100 - LEN(name)) + city_id
END COLLATE Modern_Spanish_CI_AI,
CONSTRAINT report_pk PRIMARY KEY (report_id)
);
/* Report name is unique per city (and among city-less rows) */
CREATE UNIQUE INDEX report_idx1 ON report (unique_name);
当我运行这个语句时,我收到了以下警告:
“警告!最大键长度为900字节。索引'report_idx1'的最大长度为8000字节。对于某些组合较大的值,插入/更新操作将失败。”
有没有办法告诉SQL Server该列不会超过106个字符,以便消除警告?