We want to create Hashbytes computed column Non-Persisted. Table has twenty columns, and would like to exclude IdentityId column. How could I do this in computed column? Is there a SQL library function to exclude certain column? Purpose is for easy maintenance and as columns get added, don't want developers to forget adding extra columns. So hashbyte should always take all columns, exclude identity.
This is manual way typing all the columns:
CREATE TABLE [dbo].[CustomerTransactiont]
(
CustomerTransactionId int primary key identity(1,1),
CustomerName varchar(255),
Price decimal(10,2),
Quantity int,...
.....
RowHash as hashbytes('SHA2_512', CONCAT(CustomerName,'|'
,Price), '|'
,Quantity), '|'...
))
)
Reference:
How to create a Hash Computed Column for Many Columns?
Best Answer
You could script this as part of your release process. EG something like: