January 5, 2006 at 9:32 am
I am using the follwing trigger where it updates all records in lastmodified column to current date when there is an update on the table but wht i need is, i just want to update only those records where there is a an update . pls help.
CREATE TRIGGER Q_U on dbo.Quarter
FOR UPDATE
AS
BEGIN
UPDATE Quarter
SET LastModified = getdate()
END
January 5, 2006 at 9:38 am
To say directly what i need...
I have to get the modified date n time automatically of a single record when it is changed. How can I do tht?
January 5, 2006 at 11:42 am
Hi..
Y u trying trigger only..u can u simple procedure also
like
create proc update_test
@id int
as
begin
update test_table
set Date_test = getdate()
where id = @id
end
Regards,
Papillon
January 5, 2006 at 11:45 am
Post the DDL of the table, or at least tell us what the primary key is, and we'll show you how to join to the inserted virtual table to update only the updated row or rows.
January 5, 2006 at 3:06 pm
Like PW said change pkey in the join for your primary key column(s)
CREATE TRIGGER Q_U on dbo.Quarter
FOR UPDATE
AS
BEGIN
if @@rowcount = 0 return
UPDATE Q SET LastModified = getdate()
FROM Quarter Q join inserted i on Q.pkey = i.pkey
END
Cheers,
* Noel
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply