SQL Server 2005 triggers

Last Post 20 Oct 2010 04:44 PM by gunneyk. 1 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
river1
New Member
New Member

--
20 Oct 2010 07:37 AM
Hi,

I have a app of witch i do not have the source code...

Some guys update several fields of the database throught this app.

One of this fileds is the "BI". I do not want that people can update this field "BI" through the app in a particular situation.

Particular situation:

This table as several fields , as i told, and when the field "BI" is updated to a new value some times the app updates the field "POSTO" to a value = "CENTRAL".

I think that the app is doing something like:


Update table set bi ='New value given by the user', Posto ='Central', Date =getdate()

So, when the field posto is equals to "Central" then the table should not permite the update. But if the filed POSTO is going to have another value, like 'Others' then the update can be done.

How can i do this using a trigger?

Can sameone help?


Thank you
gunneyk
New Member
New Member

--
20 Oct 2010 04:44 PM
One way is in the trigger you can put:

IF EXISTS(SELECT * FROM Inserted WHERE Posto = 'Central')
BEGIN
IF @@TRANCOUNT > 0
ROLLBACK TRAN
END

Or you can put a CHECK Constraint that does not allow a value = 'Central'
You are not authorized to post a reply.

Acceptable Use Policy