【发布时间】:2018-06-27 21:49:00
【问题描述】:
使用 SQL Server 2016,我遇到了一点问题。
这是给我带来问题的用例...
create table dbo.Example (
Id int identity (1, 1) not null,
[Name] nvarchar(100) not null,
Email nvarchar(255) not null,
DOB datetime2(7) not null,
RowHash as convert(nvarchar(66), hashbytes('SHA1', coalesce(
convert(nvarchar(max), [Name]),
convert(nvarchar(max), Email),
convert(nvarchar(max), DOB)
))) persisted
constraint [PK_Example] primary key clustered (Id asc)
);
drop table dbo.Example;
我收到的消息是:
消息 4936,第 16 级,状态 1,第 1 行 表 'Example' 中的计算列 'RowHash' 无法持久化,因为该列是不确定的。
当我将列设置为不持久化时,数据类型被正确解释为 nvarchar(66) 但是我希望它持久化。这个问题似乎与 datetime2 列有关,但是我的表上有多种数据类型。
所以目标是使用持久化的 hashbytes 列来保存我的表中所有值的哈希值。
有什么想法吗?
谢谢!
【问题讨论】:
标签: sql sql-server sql-server-2016