I am considering the following with regards to implementing a check constraint on a column I am calling year_month
. My objective is to have a check constraint to enforce YYYY-MM
.
- My intention is to create the column with data type:
varchar(7)
example value that would be saved from my front end:2017-08
Would I then add a regular expression to enforce only numbers, dashes and max 7 in my check constraint setup? Or could I add some sort of regular expression to check for this pattern more exactly?
Best Answer
You could try concatenating a valid 'day' on to the YYYY-MM values and use a CASE expression and the ISDATE function.