相同的长字符串(Varchar(max))获得不同的哈希值

时间:2013-05-23 15:29:44

标签: sql sql-server hash

SELECT  HASHBYTES('SHA1',Script)
  FROM dbo.Sync 
 WHERE roadmapKeY = 'CE9AD1B3-171D-4508-BB06-750A93EE7848'
   AND VERSION = 18

SELECT  HASHBYTES('SHA1',Script)
  FROM dbo.Sync
 WHERE roadmapKeY = 'CE9AD1B3-171D-4508-BB06-750A93EE7848'
   AND VERSION = 17

脚本是非常长的字符串,看起来像带有varchar(max)值的2047字符。 版本17和版本18实际上是相同的脚本但获得不同的哈希值? 我认为因为hashfunction使用引用或指针生成散列值,使得相同字符串的值不同(因为如果varchar大于255,它将使用外部空间) 我能比较两个字符串的任何解决方案我想知道两个字符串是否相同?

SELECT Script
  FROM dbo.Sync
 WHERE roadmapKeY = 'CE9AD1B3-171D-4508-BB06-750A93EE7848'
   AND VERSION = 18
   AND Script = (
           SELECT Script
             FROM dbo.Sync
            WHERE  roadmapKeY = 'CE9AD1B3-171D-4508-BB06-750A93EE7848'
              AND VERSION = 17
       )

没有哈希也不起作用,也许是同样的原因

我会把大字符串放在这里 第17版

DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'D' AND _fk_FormKey = 'EA827DA5-D417-4E8E-9439-08032C339921' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'E' AND _fk_FormKey = '4AFCF04C-CE37-43C2-A2B4-0CE9B0D606A7' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'B' AND _fk_FormKey = '425E3BA9-5EEA-4800-A4A7-14104AA01BCE' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'B' AND _fk_FormKey = '754669BD-A955-4AD4-B385-17EDE2DECAAE' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'I' AND _fk_FormKey = '821F5377-FAC5-4D9F-8A65-1AC54015BBC6' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'F' AND _fk_FormKey = '0FD298EE-4B77-4D81-9170-29E212EFC4D6' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'F' AND _fk_FormKey = '82FE6FF9-144A-4F05-9379-323BF6CDC0E1' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'A' AND _fk_FormKey = '9792EC50-C5F3-4A76-B331-373180467451' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'C' AND _fk_FormKey = '9FDC4F6E-BEF1-41B4-A259-385E6A660B65' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'A' AND _fk_FormKey = '0DB2A723-1CBB-4EC7-8C59-4149E5FF9EE2' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'F' AND _fk_FormKey = '7ADADD59-3239-4C0A-92E5-52EEB9B508C7' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'E' AND _fk_FormKey = '5F508647-23F4-4967-AB69-67CFC8E8D514' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'D' AND _fk_FormKey = '4A6B3BF7-7D11-4F63-8644-6A25D1142D15' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'K' AND _fk_FormKey = '69623C61-E884-40D8-95E9-6BC634E44420' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'C' AND _fk_FormKey = 'A99D228C-5516-430B-87D1-6BE1550FE924' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'G' AND _fk_FormKey = '616F4A68-0286-4964-A24A-73CC3EC775E5' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'M' AND _fk_FormKey = 'D36B1F0F-7107-4DBC-97F0-76381E62DB27' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'E' AND _fk_FormKey = '81690817-DB4D-4418-BFAF-7702BA499F5C' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'H' AND _fk_FormKey = '4CAF4679-5A0B-4E6D-B4B3-7B690C055EA6' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'G' AND _fk_FormKey = 'E66B6CCA-EF9B-4FE1-B98E-7B7CA6851ABC' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'F' AND _fk_FormKey = '0145AD1D-7321-4114-BE29-8807D0B3CC26' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'B' AND _fk_FormKey = '676150E3-1408-4DC0-BD28-894127DA2CCD' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'E' AND _fk_FormKey = '0DD47B03-114A-426F-89E5-8C4E5C41155F' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'L' AND _fk_FormKey = '0C2B3F72-C9B5-45BA-B81B-90E49A11795A' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'C' AND _fk_FormKey = '93D05DBC-1B59-41BB-90ED-98C00DE9F0C3' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'D' AND _fk_FormKey = 'CD1423DC-8CE1-4923-B529-A48222060D21' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'H' AND _fk_FormKey = 'C2350B8C-04C5-452B-ADA7-B745DE0C24D6' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'J' AND _fk_FormKey = '88878771-4A45-4936-8D32-B9530D5B8E09' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'I' AND _fk_FormKey = 'FE0928B3-3EC5-4D66-8450-BCC2586ADB61' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'B' AND _fk_FormKey = 'ACAAE3F4-8AA8-46D1-9152-CB8D6C85A085' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'J' AND _fk_FormKey = 'FA60385C-DE0D-4C04-8937-D6B9950067BC' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'A' AND _fk_FormKey = '08CECB30-F8E3-4BBF-BDDE-D6D21065E161' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'D' AND _fk_FormKey = '38FB9E32-9A2F-4E05-9563-D93EB7AE695D' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'K' AND _fk_FormKey = '8AAB9FE2-90A3-40E1-9641-DC15E297FD10' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'N' AND _fk_FormKey = '05E2566D-6BBD-4DB7-95E8-E594EE51D298' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'C' AND _fk_FormKey = '6DE99CAD-1A63-4382-B5A5-E6E48AC5DC26' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'L' AND _fk_FormKey = '8CFF8468-D12E-4DC9-831F-E958DEF2946D' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'A' AND _fk_FormKey = '334FA5CD-B972-4FE2-9B5F-F49F77764CB6' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'N' AND _fk_FormKey = '419DB66D-6D69-4F89-8E9A-F95E92DC3B71' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'M' AND _fk_FormKey = '0CA63E19-A969-4CA0-83CD-FAAA0724D00F' UPDATE [Live].[Test] SET _fk_RoadmapKey = 'CE9AD1B3-171D-4508-BB06-750A93EE7848',TestID = 'GRAD-Mathematics-11',ReportingInstrument = '1',SubjectCode = 'MA',SubjectName = 'Mathematics',Version = 18,Updated = 'May 23 2013 10:59AM'WHERE TestKey = '92406CB9-7F5B-4531-8C9F-5C0A4B4D6F50' UPDATE [Live].[Test] SET _fk_RoadmapKey = 'CE9AD1B3-171D-4508-BB06-750A93EE7848',TestID = 'GRAD-Reading-10',ReportingInstrument = '1',SubjectCode = 'RE',SubjectName = 'English Language Arts',Version = 18,Updated = 'May 23 2013 10:59AM'WHERE TestKey = 'FC24DAED-B9D9-4BE3-AEC7-708EF29E513F' UPDATE [Live].[Test] SET _fk_RoadmapKey = 'CE9AD1B3-171D-4508-BB06-750A93EE7848',TestID = 'GRAD-Writing-10',ReportingInstrument = '1',SubjectCode = 'WR',SubjectName = 'English Language Arts',Version = 18,Updated = 'May 23 2013 10:59AM'WHERE TestKey = '4F1615CC-BF52-46E1-8951-7B8913F2026C'

Version18:

DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'D' AND _fk_FormKey = 'EA827DA5-D417-4E8E-9439-08032C339921' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'E' AND _fk_FormKey = '4AFCF04C-CE37-43C2-A2B4-0CE9B0D606A7' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'B' AND _fk_FormKey = '425E3BA9-5EEA-4800-A4A7-14104AA01BCE' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'B' AND _fk_FormKey = '754669BD-A955-4AD4-B385-17EDE2DECAAE' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'I' AND _fk_FormKey = '821F5377-FAC5-4D9F-8A65-1AC54015BBC6' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'F' AND _fk_FormKey = '0FD298EE-4B77-4D81-9170-29E212EFC4D6' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'F' AND _fk_FormKey = '82FE6FF9-144A-4F05-9379-323BF6CDC0E1' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'A' AND _fk_FormKey = '9792EC50-C5F3-4A76-B331-373180467451' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'C' AND _fk_FormKey = '9FDC4F6E-BEF1-41B4-A259-385E6A660B65' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'A' AND _fk_FormKey = '0DB2A723-1CBB-4EC7-8C59-4149E5FF9EE2' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'F' AND _fk_FormKey = '7ADADD59-3239-4C0A-92E5-52EEB9B508C7' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'E' AND _fk_FormKey = '5F508647-23F4-4967-AB69-67CFC8E8D514' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'D' AND _fk_FormKey = '4A6B3BF7-7D11-4F63-8644-6A25D1142D15' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'K' AND _fk_FormKey = '69623C61-E884-40D8-95E9-6BC634E44420' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'C' AND _fk_FormKey = 'A99D228C-5516-430B-87D1-6BE1550FE924' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'G' AND _fk_FormKey = '616F4A68-0286-4964-A24A-73CC3EC775E5' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'M' AND _fk_FormKey = 'D36B1F0F-7107-4DBC-97F0-76381E62DB27' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'E' AND _fk_FormKey = '81690817-DB4D-4418-BFAF-7702BA499F5C' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'H' AND _fk_FormKey = '4CAF4679-5A0B-4E6D-B4B3-7B690C055EA6' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'G' AND _fk_FormKey = 'E66B6CCA-EF9B-4FE1-B98E-7B7CA6851ABC' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'F' AND _fk_FormKey = '0145AD1D-7321-4114-BE29-8807D0B3CC26' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'B' AND _fk_FormKey = '676150E3-1408-4DC0-BD28-894127DA2CCD' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'E' AND _fk_FormKey = '0DD47B03-114A-426F-89E5-8C4E5C41155F' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'L' AND _fk_FormKey = '0C2B3F72-C9B5-45BA-B81B-90E49A11795A' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'C' AND _fk_FormKey = '93D05DBC-1B59-41BB-90ED-98C00DE9F0C3' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'D' AND _fk_FormKey = 'CD1423DC-8CE1-4923-B529-A48222060D21' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'H' AND _fk_FormKey = 'C2350B8C-04C5-452B-ADA7-B745DE0C24D6' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'J' AND _fk_FormKey = '88878771-4A45-4936-8D32-B9530D5B8E09' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'I' AND _fk_FormKey = 'FE0928B3-3EC5-4D66-8450-BCC2586ADB61' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'B' AND _fk_FormKey = 'ACAAE3F4-8AA8-46D1-9152-CB8D6C85A085' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'J' AND _fk_FormKey = 'FA60385C-DE0D-4C04-8937-D6B9950067BC' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'A' AND _fk_FormKey = '08CECB30-F8E3-4BBF-BDDE-D6D21065E161' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'D' AND _fk_FormKey = '38FB9E32-9A2F-4E05-9563-D93EB7AE695D' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'K' AND _fk_FormKey = '8AAB9FE2-90A3-40E1-9641-DC15E297FD10' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'N' AND _fk_FormKey = '05E2566D-6BBD-4DB7-95E8-E594EE51D298' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'C' AND _fk_FormKey = '6DE99CAD-1A63-4382-B5A5-E6E48AC5DC26' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'L' AND _fk_FormKey = '8CFF8468-D12E-4DC9-831F-E958DEF2946D' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'A' AND _fk_FormKey = '334FA5CD-B972-4FE2-9B5F-F49F77764CB6' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'N' AND _fk_FormKey = '419DB66D-6D69-4F89-8E9A-F95E92DC3B71' DELETE [Live].[SetofClientFormIDs] WHERE [clientFormID] = 'M' AND _fk_FormKey = '0CA63E19-A969-4CA0-83CD-FAAA0724D00F' UPDATE [Live].[Test] SET _fk_RoadmapKey = 'CE9AD1B3-171D-4508-BB06-750A93EE7848',TestID = 'GRAD-Mathematics-11',ReportingInstrument = '1',SubjectCode = 'MA',SubjectName = 'Mathematics',Version = 17,Updated = 'May 23 2013 10:59AM'WHERE TestKey = '92406CB9-7F5B-4531-8C9F-5C0A4B4D6F50' UPDATE [Live].[Test] SET _fk_RoadmapKey = 'CE9AD1B3-171D-4508-BB06-750A93EE7848',TestID = 'GRAD-Reading-10',ReportingInstrument = '1',SubjectCode = 'RE',SubjectName = 'English Language Arts',Version = 17,Updated = 'May 23 2013 10:59AM'WHERE TestKey = 'FC24DAED-B9D9-4BE3-AEC7-708EF29E513F' UPDATE [Live].[Test] SET _fk_RoadmapKey = 'CE9AD1B3-171D-4508-BB06-750A93EE7848',TestID = 'GRAD-Writing-10',ReportingInstrument = '1',SubjectCode = 'WR',SubjectName = 'English Language Arts',Version = 17,Updated = 'May 23 2013 10:59AM'WHERE TestKey = '4F1615CC-BF52-46E1-8951-7B8913F2026C'

只是从数据库中复制,是不同的?

3 个答案:

答案 0 :(得分:2)

这意味着脚本不同。这可能有很多原因

  • 有什么不同吗?
  • 尾随空格(但由您拥有的SQL打折
  • 脚本中的不可打印字符(例如Unix与Windows行结尾)
  • 硬空间( )与普通空间(ASCII 160 vs ASCII 32)
  • 之类的内容

您可以与varbinary转换进行比较,以查看Hex差异

答案 1 :(得分:1)

你的字符串是不同的。也许是以一种非显而易见的方式,如空白或不可打印的字符。将它们打印为二进制文件:convert(varbinary(max), mystring)

答案 2 :(得分:0)

这两个版本肯定是不同的。不同之处在于每个脚本末尾的三个UPDATE语句。版本18脚本包含三个version = 18条目,而版本17脚本在相同位置具有version = 17个条目。 (好吧,如果你问我,那就不足为奇了。)