I have to make sure that a CHAR attribute of a class has the format of XX.XXXXX,YYY.YYYYY
. X and Y can both be positive or negative and the maxim value of both has to be -90 to 90 for X and -180 to 180 for Y (altitude and latitude). But I dont know hot to use the CHECK at all. I would also like to know where can I find info about this topic of CHECK in CHAR,INT,DECIMAL, etc. Cant find what im looking for.
Thanks.
I tried:
CHAR(18) CHECK (coordenates = '^[-]?[0-9]{2}+(\.[0-9]{5}+)?,[-]?[0-9]{3}+(\.[0-9]{5}+)?$') and 2. CHAR(30) CHECK ( CAST (SUBSTRING_INDEX(geoposicio, ",", 1) AS DECIMAL(9,6)) BETWEEN -90 AND 90
AND CAST(SUBSTRING_INDEX(geoposicio, ",", -1) AS DECIMAL(9,6)) BETWEEN -180 AND 180)
but it didn't work as you may imagine.
I expect that when I make an INSERT on the data base, it can only be a coordenate with the format I mentioned before. It doesn't have to be especifically like this (CHAR) but I'd rather not have to use other types as im new and I'm trying understand the basics of SQL.