SQL way to get the MD5 or SHA1 of an entire row

前端 未结 2 1874
一个人的身影
一个人的身影 2021-02-14 14:23

Is there a \"semi-portable\" way to get the md5() or the sha1() of an entire row? (Or better, of an entire group of rows ordered by all their fields, i.e. order by 1,2,3,

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-14 14:58

    In MSSQL -- You can use HashBytes across the entire row by using xml..

    SELECT MBT.id,
       hashbytes('MD5',
                   (SELECT MBT.*
                    FROM (
                          VALUES(NULL))foo(bar)
                    FOR xml auto)) AS [Hash]
    FROM  AS MBT;
    

    You need the from (values(null))foo(bar) clause to use xml auto, it serves no other purpose..

    提交回复
    热议问题