N
N
Nar Nar2022-01-21 19:02:36
SQL
Nar Nar, 2022-01-21 19:02:36

Is it possible to write a function that changes the value of a table automatically depending on the time?

I am writing a website for hotel booking. I want to automatically deactivate reservations if the guest does not show up.
I store the status in the reservation table. If the term has expired, then change the status to deactive. Can this be done with sql or Asp itself? I hope I was able to explain what I want to do.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Slava Rozhnev, 2022-01-21
@rozhnev

I would generally use one field for example:

create table bookings (
    id int,
    active_til datetame
);

And you don't need to edit anything.

V
Vitsliputsli, 2022-01-21
@Vitsliputsli

Scheduler on the DBMS side, or on the app side. But it's easier and better to just fix the time until which the reservation is active and check it when polling the status.

A
AVKor, 2022-01-21
@AVKor

Trigger.

V
Vasily Bannikov, 2022-01-21
@vabka

Write down the time the room was reserved.
Then periodically (via cron, HostedService, Quartz, Hangfire, stored procedures with triggers, Task Scheduler or whatever) make a request like

UPDATE bookings WHERE status IS 'ACTIVE' AND add(reservation_date, '<тут твой срок>') > now() AND guest_visited IS FALSE SET status = 'INACTIVE';
.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question