I am having trouble getting an INSTEAD OF UPDATE Trigger to update the correct row. It ends up updating all the rows in the Table. I need the View/Trigger because I am calling a UDF on some of the columns. For this example, UPPER will stand in as my UDF.
CREATE TABLE Customer_Table(Name varchar(32), Address varchar(32)); GO CREATE VIEW customer_view AS SELECT UPPER(Name) as Name, UPPER(Address) as Address FROM Customer_table; GO INSERT INTO Customer_Table values ('ABC Corp', 'San Francisco, CA'); INSERT INTO Customer_Table values ('XYZ Corp', 'New York, NY'); INSERT INTO Customer_Table values ('PQR Corp', 'Austin, TX'); GO create TRIGGER Customer_Update ON Customer_View Instead of Update AS update Customer_Table set Name = UPPER(inserted.Name), Address = UPPER(inserted.Address) from customer_table, inserted; GO update customer_view set Address = 'Brooklyn, NY' where Name = 'XYZ Corp' GO select Name, Address from customer_view
Note that when I issue the Update command, all the rows are updated, even though there is a Where clause on the Update.
How do I get the Update Trigger to update just the Row in the Where clause?
Is there something like a Current-of-Cursor in an Instead Of trigger?
Thanks.