[dba-SQLServer] trigger help

Susan Harkins harkinsss at bellsouth.net
Sat Jan 14 12:19:29 CST 2006


I'm using Express Management Studio to create a trigger that uses the
temporary inserted table to update inventory -- simple example, but I get an
error that the schema in the target table doesn't match the trigger schema.
My guess is it doesn't like the use of inserted as a table name because at
the time I'm creating the trigger it doesn't exist. If that's the case, I
don't know how to get around that. 
 
Here's the trigger:
 
CREATE TRIGGER UpdateInventory ON Sales.dbo.Orders
AFTER INSERT
AS 
BEGIN
    UPDATE Products
    SET Products.InStock = (Products.InStock - Inserted.Qty)
    FROM Products JOIN Inserted ON Products.ProdID - Inserted.ProdID
END
GO
 
I've checked the column names, just to be sure, and they above in correct in
that respect. I've run into trouble using the inserted temporary table
before, but I don't remember how I skirted it. 
 
Susan H. 
 



More information about the dba-SQLServer mailing list