1

I have a table with two columns:

assign_date | complete_date
----------------------------
2004-04-23  | 2005-05-13
 ...        |   ...

The dates are in the format yyyy-mm-yy.

When I am inserting a new row, I always want the complete_date to be at or after the assign_date. So if a row had an assign_date of 2013-10-10, 2013-10-09 would be invalid. Is there a way to do this in mysql without using triggers?

3
  • Unfortunately, I think that would require a trigger Commented Dec 19, 2013 at 0:57
  • Why "without using triggers"? Commented Dec 19, 2013 at 0:58
  • You need a trigger: While MySQL supports the CHECK clause, currently no storage engine supports it. Commented Dec 19, 2013 at 1:02

1 Answer 1

1

No, you must use a trigger to enforce this rule in the database.

Some people validate in their application before inserting the row. But this is error-prone because developers can forget to do the check in every case of inserting or updating data. Or someone can update the data directly without using an application.

Sign up to request clarification or add additional context in comments.

2 Comments

It isn't clear why the OP has ruled out triggers. Perhaps the question is purely hypothetical, in which case it must be worth at very least noting that one might be able to compile a table of every possibly valid combination and then enforce a composite foreign key constraint. But otherwise I certainly agree that triggers are the correct (and only practical) solution to the described problem in MySQL.
Thanks for the answer/comments everyone. Yes, I was engaging in hypotheticals; I wanted to see if there was another practical solution besides triggers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.