开发者

Sql prevent row being modified

开发者 https://www.devze.com 2022-12-31 23:24 出处:网络
Is it possible to prevent any changes to a row in sql? Let\'s say the record is created. But once it\'s created I don\'t want the record to be modified ever.

Is it possible to prevent any changes to a row in sql?

Let's say the record is created. But once it's created I don't want the record to be modified ever.

So the user can still try to do a update table set column = value .. but that would raise an error preventin开发者_如何学JAVAg it to be modified something like that.


yes you could do it with a trigger provided that the user doesn't do something like this

alter table disable trigger
update table...

you can also deny update on that column like this (SQL Server 2005 and up syntax)

DENY UPDATE ON OBJECT::TableName(ColumnName) TO UserNAme;


you should put a trigger on the table.

the trigger can either replace any new values with the old values, silently refusing the update, or it can throw an exception to the user saying update is not allowed.

OR

you can assign INSERT privilege to the users, but not UPDATE privilege.


The easiest way would be to REVOKE UPDATE ON TABLE, if SQL server allows for such fine grained access control.

Note that a malicious user could still DELETE, then INSERT another "changed" record.

0

精彩评论

暂无评论...
验证码 换一张
取 消