Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need a trigger that updates a table row field by checking date that is stored in their own field without any interaction of user. i.e I am working on a project where I have to book rooms for user for a particular date and time and at that case I want to show room status as "booked" but after expiry of that date and time our database automatically update room status "booked" to "available". means I want that database keep track of their record and update it automatically. How I can achieve this?

share|improve this question
Don't use a trigger for this. Just put whatever logic you were going to put into the trigger to determine this into the SELECT query instead. You can encapsulate the logic in a (non persisted) computed column on the table. – Martin Smith Oct 18 '12 at 7:12
And one important point I forgot to mention is that you can't create a trigger that fires at a specific time anyway. – Martin Smith Oct 18 '12 at 8:00

As Martin Smith said in the comments, there is no Date/Time based trigger, therefore you have two options.

  1. Batch Update - Use a batch process to update the data. This requires determining how often the data needs to change and then creating a batch process that runs at least that often to update the data. If the information changes once a day this might be acceptable, but as the update need gets more frequent this solution becomes less usable.
  2. Dynamic Evaluation - As Martin Smith suggested, determine availability when the information is requested. This can be in the select statement itself or you can use a computed column on the table. In either case the data will be as up to date as it can be.
share|improve this answer

In MySQL, I have used Event Scheduler. There is a similar function in SQLServer 2008, see Creating and Attaching Schedules to Jobs.

For your purpose, you can set it to start everyday at 00:01.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.