Question:
In our SQL-Server 2005 database, we have a table T_Groups.
T_Groups has, amongst other things, the fields ID (PK) and Name.
Now some idiot in our company used the name as key in a mapping table…
Which means now one may not alter a group name, because if one does, the mapping is gone…
Now, until this is resolved, I need to add a restriction to T_Groups, so one can’t update the group’s name.
Note that insert should still be possible, and an update that doesn’t change the groupname should also be possible.
Also note that the user of the application & the developers have both dbo and sysadmin rights, so REVOKE/DENY won’t work.
How can I do this with a trigger ?
Depending on your application framework for accessing the database, a cheaper way to check for changes is Alexander’s answer. Some frameworks will generate SQL update statements that include all columns even if they have not changed, such as
The
UPDATE()function merely checks whether the column is present in the statement, not whether its value has changed. This particular statement will raise an error usingUPDATE()but won’t if tested using the more elaborate trigger as shown above.