RE: SQL question: check constraints on strings
Posted in 1998
Uday Shankar wrote: > Hi, > > I have a question that I can't seem to find an answer to in the > IIUG FAQ or the Informix documentation. > > I have a column (char strings) in which I want a check such that if a > string I attempt to insert into > that column starts with the substring STK, then I want the string to be > of the format: > > STK.---.--- > > Else, it doesn't have to follow any particular format. > > Is there a way to achieve this ? I looked at the check constraints but > that doesn't seem to help. > > Any help will be appreciated. > > Thanks, > > Uday Uday: A check constraint should do it for you. Something along the lines of: CHECK (somecol MATCHES "STK.???.???" OR somecol NOT MATCHES "STK*") CONSTRAINT somecol_stk_chk; I haven't tested it, but there's no reason why it shouldn't work. The = guts of a CHECK clause are just a 'condition' segment. How quick it will = be is another story altogether..... cheers RET +------------------------------------------+ | Richard Thomas | | DBA - Marketing Information Systems | | Optus IT | | email: richard_thomas@yes.optus.com.au | | Ph: +61 2 9342 7188 | | "My opinions are my opinions" | +------------------------------------------+