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
 General SQL Server Forums
 New to SQL Server Programming
 Problem with trigger in sqlserver

Author  Topic 

lakshmireddym
Starting Member

6 Posts

Posted - 2006-06-30 : 07:58:43
Hi,I have a trigger in mysql as below...I need to change it into sqlserver.I am unable to find replacement to 'for each row'.Can u please let me know how can we change this trigger into sqlserver format.
CREATE TRIGGER TGR_ENTITY_TYPE_ON_ADD
BEFORE INSERT
ON ENTITY_TYPE
FOR EACH ROW
SET NEW.DATE_ADDED=NOW(),
NEW.DATE_MODIFIED=NOW();
Thanks in advance,
MLR

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-06-30 : 08:20:31
You have to have a column that identifies each row.

The DATE_ADDED columns doesn't need to

UPDATE ENTITY_TYPE
SET DATE_ADDED = GETDATE()
WHERE DATE_ADDED IS NULL
For DATE_MODIFIED you can use something like this
UPDATE ENTITY_TYPE
SET DATE_ADDED = GETDATE()
WHERE UniqueCol IN (SELECT UniqueCol FROM inserted)

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-30 : 08:48:46
quote:
CREATE TRIGGER TGR_ENTITY_TYPE_ON_ADD
BEFORE INSERT
ON ENTITY_TYPE
FOR EACH ROW
SET NEW.DATE_ADDED=NOW(),
NEW.DATE_MODIFIED=NOW();


Where did you find such code?
Read about Triggers in sql server help file for proper systax

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -