We help IT Professionals succeed at work.

what's the syntax to create an trigger

hi, i need to create an trigger that update some rows one time per day. what's the syntax to create an trigger and execute an update query?
Comment
Watch Question

Database Architect - Dba - Data Scientist
CERTIFIED EXPERT
Commented:
I am not sure I understand what you are trying to accomplish.  A trigger is to be fired on each operation happening be it an UPDATE, and INSERT or a DELETE.  In the content of the trigger you can do any operation.  The syntax for running an UPDATE on any UPDATE operation would look like


CREATE TRIGGER updater
ON dbo.YOURTABLENAME
AFTER UPDATE
AS
   UPDATE some othertable
GO

Now if you need to run an update only once a day, I'd recommend creating a job to be ran once a day and schedule the UPDATE at the time you wish.
Commented:
"one time per day" isnt supported by triggers (which fire upon certain EVENTS in the database
what you need for this is an Agent job. the agent in sql can be set to run at predefined times and run a predefined job (which may include updating tables like you wanted)
if you are using express version of sql, youll need to find another way  cause sql agent isnt included
OR
try to think if there is actually an event in the databse that can be used to "trigger" the update (like some data change that happens every day anyway...)
Racim BOUDJAKDJIDatabase Architect - Dba - Data Scientist
CERTIFIED EXPERT

Commented:
@ErezMor

Thanks for reexplaining what was already explained above :)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.