Assume that I know that updating a primary key is bad.
There are other questions which imply that the inserted
and updated
table records match by position (the first of one matches the first of the other.) Is this a fact or coincidence?
Is there anything that could join the two tables together when the primary key changes on an update?
SQL Server COLUMNS_UPDATED() Function for Triggers. This function is used to know the inserted or updated columns of a table or view. It returns a VARBINARY stream that by using a bitmask allows you to test for multiple columns.
In DML triggers, the inserted and deleted tables are primarily used to perform the following: Extend referential integrity between tables. Insert or update data in base tables underlying a view. Test for errors and take action based on the error.
Expand Triggers, right-click the trigger to delete, and then click Delete. In the Delete Object dialog box, verify the trigger to delete, and then click OK.
Triggers are used to maintain referential integrity, which assures that vital data in your databaseľsuch as the unique identifier for a given piece of dataľremains accurate and can be used as the database changes. Referential integrity is coordinated through the use of primary and foreign keys.
There is no match of inserted+deleted virtual table row positions.
And no, you can't match rows
Some options:
Each table is allowed to have one identity column. Identity columns are not updateable; they are assigned a value when the records are inserted (or when the column is added), and they can never change. If the primary key is updateable, it must not be an identity column. So, either the table has another column which is an identity column, or you can add one to it. There is no rule that says the identity column has to be the primary key. Then in the trigger, rows in inserted and updated that have the same identity value are the same row, and you can support updating the primary key on multiple rows at a time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With