views:

527

answers:

3

Hi all,

I want to create a table trigger for insert and update. How can I get the values of the current record that is inserted/updated?

+6  A: 

within the trigger, you can use a table called 'inserted' to access the values of the new records and the new version of the updated records. Similarly, the table called 'deleted' allows you to access deleted records and the original versions of updated records.

Ray
A: 

using function 'update' on column ( if you wanna check the fact of update) or retrieving rows from table 'inserted'

Balend
A: 

While triggers can be used for this, I'd be very careful about deciding to implement them. They are an absolute bear to debug, and can lead to a lack of maintainability.

if you need to do cascading updates (i.e. altering table A in turn changes table B), I would either use a stored procedure (which can be tested and debugged more easily than a trigger), or if you're fortunate enough to be using an ORM (Entity framework, NHibernate, etc.) perform this function within your model or repository.

Bob Palmer