This is my first time creating a trigger, so please bear with me. I've looked through SQL Server Books Online, Google groups, and these forums, but it's still not clicking. Here's what I'm trying to do.
I've got a table which I'd like to create a trigger for. When a row gets inserted, I want the trigger to fire. When the trigger fires I want it to analyze data in two of the columns of the newly inserted row and perform a calculation. Then, I want it to update a third column in the newly inserted row with the value from that calculation.
I'm also looking to create another trigger (or modify the trigger above) so that when either of the two columns mentioned above are updated, the trigger will fire. It will run the same anaylsis/calculation on those two columns and update the third column of the updated row with the value from that calculation.
I'm using a GUID in the table that I want to create the trigger for. To determine what the GUID so I can perform the necessary SELECT and UPDATE commands, I need to be able to determine the GUID of the newly inserted or updated rows. I understand there is an INSERTED and DELETED table that I can reference, but I'm not clear on how those work. I know those tables can be used to see what data was inserted or deleted, but are the tables unique to each INSERT, UPDATE, or DELETE command that is run? Or, does it house the data from all INSERT, UPDATE, and DELETE commands that have been run?
I'm sure once I get the trigger in place, I'll be able to understand what's going on a little better. Any suggestions?
I've got a table which I'd like to create a trigger for. When a row gets inserted, I want the trigger to fire. When the trigger fires I want it to analyze data in two of the columns of the newly inserted row and perform a calculation. Then, I want it to update a third column in the newly inserted row with the value from that calculation.
I'm also looking to create another trigger (or modify the trigger above) so that when either of the two columns mentioned above are updated, the trigger will fire. It will run the same anaylsis/calculation on those two columns and update the third column of the updated row with the value from that calculation.
I'm using a GUID in the table that I want to create the trigger for. To determine what the GUID so I can perform the necessary SELECT and UPDATE commands, I need to be able to determine the GUID of the newly inserted or updated rows. I understand there is an INSERTED and DELETED table that I can reference, but I'm not clear on how those work. I know those tables can be used to see what data was inserted or deleted, but are the tables unique to each INSERT, UPDATE, or DELETE command that is run? Or, does it house the data from all INSERT, UPDATE, and DELETE commands that have been run?
I'm sure once I get the trigger in place, I'll be able to understand what's going on a little better. Any suggestions?