Click to See Complete Forum and Search --> : Triggers
danasegarane
07-27-2006, 11:24 PM
I want to create a trigger that inserts the current time whenever i insert or update a row automatically. How can I.The two fields are creation_time and modified time. The modified time should be updatee whenever i edit the to rows. The sever is MSSql and my table name is tbl_transaction.
russell
07-27-2006, 11:54 PM
CREATE TRIGGER myTrigger
ON myTable
AFTER INSERT, UPDATE
AS
UPDATE myTable
SET modifiedTime = CURRENT_TIMESTAMP
WHERE id = (select id from _INSERTED)
GO
http://msdn2.microsoft.com/en-us/library/ms189799.aspx
danasegarane
07-28-2006, 01:35 AM
I want to insert the date only.How can I format the time as dd/mm/yyyy or mm/dd/yyyy
russell
07-28-2006, 12:57 PM
Convert(smalldatetime, Left(current_timestamp, 11), 101)
danasegarane
07-29-2006, 08:52 AM
Dear Rus ,
I am getting the following error msg
russell
07-29-2006, 09:23 AM
sorry, that is a stray underscore. should be inserted not _inserted.
check out BOL for Create Trigger and inserted tables