8protons
8protons

Reputation: 3959

Is there a way to protect all existing rows from being edited in an SQL table?

Assume a developer has a table of records that they do not want edited, as the values are sensitive and generated based on the environment in that moment. For integrity purposes- records within the table can be added, never edited.

In the model, the programmer has set access modifiers such that only a constructor can set the properties but once they are set, they cannot be modified (barring reflection).

How can one instill this same concept into rows within a table?

Upvotes: 1

Views: 517

Answers (2)

Ankur Patel
Ankur Patel

Reputation: 1423

If you do not wish to use to user permission then you can create a before update/delete trigger and raise error inside that trigger which will not allow the user to update any record. Though a user who has access permission to trigger can modify or drop the trigger.

Upvotes: 2

Kousalik
Kousalik

Reputation: 3137

The table can be protected by revoking the database users rights to UPDATE and DELETE. This solution is then implemented on a per user level.

Similar concept exists in all major database systems. More info on permissions (Oracle):https://www.techonthenet.com/oracle/grant_revoke.php

You could also use a trigger before UPDATE/DELETE to raise an error, which will prevent the change also for users, which have not been revoked the permissions. More info on triggers (Oracle): https://www.techonthenet.com/oracle/triggers/before_update.php

Upvotes: 7

Related Questions