-1

I have two tables A and B, both having timestamp field in it and one of the timestamp is 4 days ahead of the other.

e.g A timestamp is today B timestamp is today+4 days

Is it possible to create triggers in sql that automatically keeps on checking the difference of the timestamp and throw a result once A.timestamp - B.timestamp = 0 or is there any way of doing it.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
maverick
  • 37
  • 1
  • 10
  • 1
    How do tables have "a timestamp"? Tables have rows, so I would expect there to be as many timestamps as there are rows. Please show sample data, desired results, and tag your question with the correct database. – Gordon Linoff Oct 11 '16 at 01:41
  • Possible duplicate of [Store Procedure that Automatically delete rows older than 7 days in MYSQL](http://stackoverflow.com/questions/32507258/store-procedure-that-automatically-delete-rows-older-than-7-days-in-mysql) – Drew Oct 11 '16 at 01:52
  • Depending on your platform, Events or Jobs or similar, this powerful layer most likely and somewhat simply removes the need for `cron`. See this [ms sql-server](https://www.mssqltips.com/sqlservertutorial/2209/mysql-to-sql-server-scheduling-tasks-differences/) article – Drew Oct 11 '16 at 01:57
  • 2
    Triggers and such are **highly** vendor-specific - so which RDBMS is this for? Please add a tag to specify whether you're using `mysql`, `postgresql`, `sql-server`, `oracle` or `db2` - or something else entirely. – marc_s Oct 11 '16 at 05:15
  • Are you looking for a check constraint? `check (timestamp_a + interval '4' day <= timestamp_b)` –  Oct 11 '16 at 06:06
  • Why do you store data like that, with a 4 day difference between the tables? And, the answer is yes, it's possible. – jarlh Oct 11 '16 at 07:09

1 Answers1

0

Triggers are always "triggered" if data is modified in some way.

I understand that you want is a cron instead. You can create a stored procedure which will do the check and insert the result in another column. Then you can call this stored procedure in a timer In your database. And if your database doesn't support it. You can always create a task schedule in windows or cron in Linux and call a program which will call the stored procedure or make the change directly on SQL

Carlos Rafael Ramirez
  • 5,984
  • 1
  • 29
  • 36