SQL server writes a column once

Is there a way to configure an instance of SQL Server to not allow updates to values ​​inserted into the database?

eg. after insertion, the value is fixed, other columns in the same row can be changed, but this value is written only once.

+3
source share
1 answer

Write an update trigger that checks the current column for the newly inserted value and rolls back the transaction if the values ​​are different.

create trigger dbo.tr_no_updates
on mytable
for update
as
if update(mycolumn)
   rollback transaction
+5
source

Source: https://habr.com/ru/post/1707147/


All Articles