- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用的是 SQL Server 2008。
我有一个名为 Title 的 NVARCHAR(MAX) 列,我想为其添加唯一索引。由于该列大于 900bytes ,我决定创建一个 HashBytes 计算列(基于 StackOverflow 上的推荐)。
如何创建 HashBytes 列?
alter table Softs add TitleHash AS (hashbytes('SHA1',[Title])) PERSISTED;
这有效并创建了计算列。
但是当尝试添加索引时,我收到以下错误:
Adding the selected columns will result in an index key with a maximum length of 8000 bytes.
The maximum permissible index length is 900 bytes.
INSERT and UPDATE operations fail if the combined value of the key columns exceeds 900 bytes.
Do you want to continue?
这是用于创建索引的查询:
CREATE NONCLUSTERED INDEX [UIX_TitleHash] ON [dbo].[Softs]
(
[TitleHash] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
最佳答案
hashbytes 列被创建为 VARBINARY(MAX)
除非您明确告诉它 20 个字节就足够了:
alter table dbo.Softs
add TitleHash AS CAST(hashbytes('SHA1', [Title]) AS VARBINARY(20)) PERSISTED
完成此操作后,您可以在该列上创建索引(是否唯一):
CREATE UNIQUE NONCLUSTERED INDEX [UIX_TitleHash]
ON [dbo].[Softs]([TitleHash] ASC)
现在应该可以正常工作了。
关于.net - SQL Server 2008 - HashBytes 计算列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3696504/
有关函数HashBytes请参考:http://msdn.microsoft.com/en-us/library/ms174415.aspx 在做项目的时候,在sql中使用了hashbytes
我需要执行此 Sql 命令(在管理工作室中运行良好): select * from Users where Login = 'test' and PasswordHash = HashBytes('S
我正在尝试使用 hashbytes 命令更新 SQL Server r2 上的列。这是该命令的简化版本: COMMAND: "UPDATE [tbl] SET [checksum] = HASHBYT
在我的应用程序中,HASHBYTES SQL 函数为同一字符串返回不同的值。下面是我的用户创建代码。 Guid fillerG = Guid.NewGuid(); using (SqlCommand
我正在将我的数据从 SQL Server 移动到 MySQL。数据移动没有任何问题,但我正在尝试想出一种方法来验证 SQL Server 和 MySQL 之间数据的完整性。我在数据类型 VARCHAR
我有一个复杂的查询,它使用了大量的二进制校验和函数,当我使用两个不同记录的一些测试数据对其进行测试时,它实际上返回了相同的校验和值。请在下面找到我使用的测试数据 SELECT BINARY_CHECK
我想获取 SQL Server 2005 中字符串值的 MD5 哈希值。我使用以下命令来执行此操作: SELECT HashBytes('MD5', 'HelloWorld') 但是,这会返回 Var
我正在使用 SQL Broker 和 SQL CLR 将大量 XML 推送到我的企业服务总线 (ESB) 以供消费者使用拾取和处理。为了“审核” OUTGOING XML(我将其匹配)与服务总线接收的
select HASHBYTES('SHA2_256', 'hi'); 它应该编码“hi”,但它只返回此错误: [Exception, Error code 1,305, SQLState 42000
我编写了一个存储过程,用于散列特定列的值。我需要在 CASE WHEN 或 IIF 语句中使用此 HASHBYTES 函数,如下所示: DECLARE @Hash varchar(255) = 'te
将此函数的输出从 varbinary() 转换为 varchar() 的最有效方法是什么? 最佳答案 这个怎么样: master.sys.fn_varbintohexstr(@binvalue) 关于
我使用的是 SQL Server 2008。 我有一个名为 Title 的 NVARCHAR(MAX) 列,我想为其添加唯一索引。由于该列大于 900bytes ,我决定创建一个 HashBytes
有没有相当于 CHECKSUM_AGG(CHECKSUM(*)) 对于哈希字节? 我知道你可以 SELECT HashBytes('MD5', CONVERT(VARCHAR,
我有一个简单的 SqlConnection 代码,其中有一个 HASHBYTES 函数来从我的服务器检索数据。 using (var connection = new SqlConnection(co
有人可以向我解释为什么不使用 T-SQL SELECT substring(master.dbo.fn_varbintohexstr(hashbytes('MD5', 'HelloWorld')),
我正在尝试将HASHBYTES与SHA2_512一起使用。但是,当我尝试在SQL Server Management Studio中执行此操作时,得到的所有内容都是null。 SELECT HASHB
我尝试计算某个值的 md5 哈希值,但我得到了一个奇怪的结果。 我以两种不同的方式运行它: SELECT HASHBYTES('md5',ZLA_PASSWORD),ZLA_PASSWORD, len
我在 sql 中使用以下函数创建了哈希值 SQL查询 Select hashbytes('MD5', PNumber+CONVERT(VARCHAR(50),cast(datestamp as bi
如果我在 SQL Server 中运行以下命令: SELECT HASHBYTES('SHA2_512', 'THE CAT SAT ON THE MAT') 然后在 C# 中运行它 string t
我有一个简单的问题: print HASHBYTES('SHA1', 'az09123') 给我: 0xA00592FC3E531C5F7608110F73E8AE4B4F2EA4C3enter 我把
我是一名优秀的程序员,十分优秀!