Is there a Before Update Trigger with SQL

  • Thread starter Jeff via AccessMonster.com
  • Start date
J

Jeff via AccessMonster.com

I would like to set the User_Name() and GetDate() in a table before my
insert and update triggers start. Is there a way of doing this before the
trigger? Right now I update these fields after the trigger but it ends up
causing an unnecessary re-trigger to update the fields and I don't want to
set the username and date on the front-end.
 
G

Graham R Seach

Jeff,

As with Jet, you can define a DefaultValue in SQL Server, using GetDate()
and SUSER_SNAME(). But SQL Server also allows you to specify INSTEAD OF
triggers, like so:

CREATE TRIGGER procMyInsteadProc ON dbo.Table1
INSTEAD OF INSERT
AS
INSERT INTO Table1 (MyDate, MyUser)
VALUES (DateAdd(month, 1, GetDate()),
SUSER_SNAME() + ' eats worms!')

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top