hash a SQL row?

后端 未结 4 576
情歌与酒
情歌与酒 2020-12-29 23:32

Is there a way to md5sum a row in a SQL table to check whether any column has been modified?

I would like to check whether any particular column has been changed ver

4条回答
  •  温柔的废话
    2020-12-29 23:59

    If you have SQL Server 2008 or newer you could use:

    SELECT HASHBYTES('SHA1', (SELECT TOP 1 * FROM dbo.Table FOR XML RAW))
    

    or

    SELECT  
        HASHBYTES('SHA1',(
            SELECT  * 
            FROM    dbo.myTable as  tableToHash 
            where   tableToHash.myUniqueKey=myTable.myUniqueKey 
            FOR XML RAW
        ))                                              as  rowSHA1
    from    dbo.myTable;
    

提交回复
热议问题