Question: Trigger Exercise Write a trigger that fires anytime an insert or update occurs on the Invoice table. The trigger will need to write the following

Trigger Exercise

Write a trigger that fires anytime an insert or update occurs on the Invoice table. The trigger will need to write the following information to a ChangeLog table.

ChangeID int identity(1,1) primary key InvoiceID int (will contain the ID of the invoice being changed) ChangedBy nvarchar(30) (will contain the login of the user making the change) DateChanged smalldatetime (will contain the date of the change) OldInvoiceTotal money (will contain the old value found in the deleted temp table) NewInvoiceTotal money (will contain the new value found in the inserted temp table)

On an insert both the OldInvoiceTotal and the NewInvoiceTotal will be the same. Make sure you test your trigger for and update situation where the InvoiceTotal is changed. This trigger should fire off when you run your stored procedure from above. This table is very similar to the one you created for the Northwind trigger exercise.

Invoices AS Orders.ShipName, Orders.ShipAddress, Orders.ShipCity, Orders.ShipRegion, Orders.ShipPostalCode, Orders.ShipCountry, Orders.CustomerID, Customers.CompanyName AS CustomerName, Customers.Address, Customers.City, Customers.Region, Customers.PostalCode, Customers.Country

Note: Name your trigger as Test02_tr.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!