views:

17

answers:

1

Hi, i have a table with two column {FlatContent, HashedContent}. Now i want to automatically compute hash value of FlatContent when new row was inserted or an existing row was updated. To date, i'm never used from trigger, so i can't do this by trigger or another approach which is exist to solve this issue.

Thanks if anybody can help me ;)

+2  A: 

Instead of using a trigger, make HashedContent a persisted computed column in your table definition.

ALTER TABLE YourTable
    ADD HashedContent AS HashBytes('SHA1', FlatContent) PERSISTED
Joe Stefanelli
@Joe Thanks but i think i can't use this feature because i'm use of varbinary data-type and i can't turn IsPersisted option on!
Sadegh
@Sadegh: You could still create the computed column without the PERSISTED option. You just wouldn't be able to index it.
Joe Stefanelli
@Joe Now I'm going to do this. Thanks Joe ;)
Sadegh