I need help regarding my sql project.
I have a table in which football results in column as VARCHAR. And I want to make it impossible to insert data into them other than in this format: number:number
For example: 2:1, 0:0, 10:0 and so on. Is it possible to set it to only this way?
Thank you.
2
Answers
As suggested in the comments, it would be better to put the values in two separate
INT
columns. But if you really must do it this way, you can use aCHECK
constraint to test the format using a regular expression.try this
ALTER TABLE football_results
ADD CONSTRAINT score_format CHECK (score LIKE ‘[0-9]:[0-9]’)