September 11, 2007 at 3:26 am
Quick question here, I'm doing an update trigger, in the trigger code how do I restrict it from updating a certain column, e.g. say a teacher is updating the details of a "Course" table and he should be able to update all of them except the "Course Name" column.
September 11, 2007 at 3:43 am
You can access the old and new values via the inserted and deleted tables. I assume you also have a PK column, so if you join these two tables on the PK, and check if the two non-modifiable columns are the same, you will know that the user has modified the column or not. If the user modified, you can roll back the transaction.
Andras
September 11, 2007 at 3:45 am
You could also look at COLUMNS_UPDATED ( )
http://technet.microsoft.com/en-us/library/ms186329.aspx
Andras
September 11, 2007 at 3:52 am
That seems rather complex, I think there should be an easier way (if not I guess I will have to try your suggestion). Plus I don't want to rollback transaction, I still want the update to go through but not update the particular "Course Title" column (maybe just print to the results 'that column could not be updated'), but it should update all other columns.
September 11, 2007 at 3:58 am
You could also use UPDATE (restrictedColumn) this returns true or false for a particular column.
Andras
September 11, 2007 at 1:50 pm
That sounds like a CLIENT side issue. If you need to enforce that on the server Use a view to restrict the columns that can be updated and run the update on the view.
* Noel
September 11, 2007 at 7:34 pm
No need for a trigger... You can revoke permissions from individual users by column in a table or view. Lookup REVOKE in Books Online for the full syntax.... but here's a simplified example...
REVOKE UPDATE ON yourtablename (yourcolumnname)
FROM securityaccount_or_loginname
--Jeff Moden
Change is inevitable... Change for the better is not.
September 11, 2007 at 9:25 pm
Hmm, I might need to check the specification, but I don't think this is about users, I'm pretty sure there is just one user, the administrator and technically he has access to everything, but when calling an
UPDATE Course
SET "Course Name" = newcoursename
This should not be allowed but all other column updates should be allowed.
Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply