October 16, 2006 at 1:49 am
Hello everyone, i have 2 tables table1: "Transactions" and table2: "TransactionLog",
In table1 i have the following fields::::::::::::::::
TransactionID ,
BuyerID,
TransactionTypeID,
TransactionStatusCode,
PaymentModeID,
SubAccountNumber,
IsDebit,
TransactionDate,
DispatchDate,
ExpireDate,
LastStatusUpdate,
TotalAmount,
Discount,
Tax,
PaymentServiceFees,
InstrumentNumber,
Comments
In table2 i have following fields::::::::::::::::::
TransactionID,
TransactionStatusCode,
LogDate,
ErrorCode,
Comments.
......................................................................
Now i want to write a trigger for Insert and Update on table1. As if any insertion is made in the table1 or update anything in tha table1 , for this a new entry is always added in table2. ( for making log activity)
i never used triggers so plz give me solution with code
its very urgent
plz plz plz reply me asap
October 18, 2006 at 9:23 am
something like:
CREATE TRIGGER tr1 ON Transactions
AFTER INSERT,UPDATE AS
INSERT INTO TransactionLog(TransactionID, TransactionStatusCode, LogDate, ErrorCode, Comments )
--the table [INSERTED] is the data being affected by insert/update:
SELECT TransactionID, TransactionStatusCode, LogDate, ErrorCode, Comments FROM [INSERTED]
Lowell
October 20, 2006 at 6:37 am
Only I would use GetDate() for LogDate. So, it would seems like the following:
CREATE TRIGGER tr1 ON Transactions
AFTER INSERT,UPDATE AS
INSERT INTO TransactionLog(TransactionID, TransactionStatusCode, LogDate, ErrorCode, Comments )
SELECT TransactionID, TransactionStatusCode, GetDate(), ErrorCode, Comments FROM [INSERTED]
Matter of taste, really.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply