Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 error in trigger

Author  Topic 

asifbhura
Posting Yak Master

165 Posts

Posted - 2011-08-01 : 12:38:34
Hello Sir,

I created trigger as below

ALTER TRIGGER SetCreation_date ON dbo.Content_Header
after update
AS
update dbo.Content_Header set CreationDate=getdate()
GO

it updates all records, i want to be set getdate() on only updated records,

So,I tried like below

ALTER TRIGGER SetCreation_date ON dbo.Content_Header
after update
AS
update dbo.Content_Header set CreationDate=getdate() FROM UPDATED
GO

but doesnt work...

How can i set getdate on only updated record

Regards,

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-01 : 12:47:00
you should be using inserted or deleted tables for this

ALTER TRIGGER SetCreation_date ON dbo.Content_Header
after update
AS
update c set
c.CreationDate=getdate()
FROM dbo.Content_Header c
INNER JOIN INSERTED i
ON i.OK= c.PK
GO

PK is your primary key column

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

asifbhura
Posting Yak Master

165 Posts

Posted - 2011-08-01 : 17:03:31
thanx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-02 : 01:02:01
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -