SQL Server 2008 R2 Trigger
Asked By: LaLa
Originally Asked On: 2014-01-02 11:35:01
Asked Via: stackoverflow
I know there have been a plethora of Q’s asked around this but after reading, nobody seems to have the same trouble as I do.
Background Info: I am looking to doing incremental updates into a Cube, but have no timestamp of update on the table. I now am looking at creating a standalone table which updates via a trigger with the gkey and current datetime stamp, when a record is updated.
My trigger on the table is as follows:
CREATE TRIGGER trgAfterUpdateVisitDetails ON [visit_details] FOR UPDATE AS begin declare @VD_Gkey nvarchar declare @today DATETIME = SYSDATETIME() insert into [UpdatedVD] SELECT @VD_Gkey, @today FROM [visit_details] End
This gives me an output like below but with 917 lines of the same:
+---------+-------------------------+ | VD_Gkey | today | +---------+-------------------------+ | NULL | 2014-01-02 11:21:23.963 | | NULL | 2014-01-02 11:21:23.963 | +---------+-------------------------+
I know it’s going to be something pretty simple but I cannot get my head around this.
Any help would be brilliant.
Thanks.
He received 1 answers
eventually accepting:
StuartLC’s answer to
SQL Server 2008 R2 Trigger
You just need to access the
inserted
anddeleted
pseudo-tables:CREATE TRIGGER trgAfterUpdateVisitDetails ON [visit_details] FOR UPDATE AS begin insert into [UpdatedVD] SELECT i.VD_Gkey, CURRENT_TIMESTAMP FROM inserted i; End
If the selected answer did not help you out, the other answers might!
All Answers For: SQL Server 2008 R2 Trigger
StuartLC’s answer to
SQL Server 2008 R2 Trigger
You just need to access the
inserted
anddeleted
pseudo-tables:CREATE TRIGGER trgAfterUpdateVisitDetails ON [visit_details] FOR UPDATE AS begin insert into [UpdatedVD] SELECT i.VD_Gkey, CURRENT_TIMESTAMP FROM inserted i; End
Of course, you should really check out the original question.
The post SQL Server 2008 R2 Trigger [ANSWERED] appeared first on Tech ABC to XYZ.