I have a two database tables,that database tables connect with 1:1 relationship.Using a trigger i need to copy some coloumns data to Log table.(When New Insert or Update Happens)
Error (1) Invalid column name 'ItemTbl_ItemId'.
(2) Invalid column name 'Price'
(3)Column name or number of supplied values does not match table definition.
First Table has
Table Name - ItemTbl
ItemId, ItemName, ItemPrice,Comments, Brand_BrandId
Second Table
Table Name - ItemLog
ItemLogId, ItemTbl_ItemId,ItemName,ItemPrice,ModifiedDate
My Trigger
CREATE TRIGGER [dbo].[ItemHistoryTrigger]
ON [dbo].[ItemTbl]
FOR INSERT,UPDATE
AS
BEGIN
IF EXISTS(SELECT ItemId,ItemName,ItemPrice FROM INSERTED)
BEGIN
INSERT INTO [dbo].[ItemLog]
SELECT ItemTbl_ItemId,ItemName,ItemPrice FROM INSERTED;
END
END
I Just wanted to copy ItemName & ItemPrice from the first table to second table using trigger.