sql Constraint Checks

Discussion in 'Databases' started by Silver89, Feb 5, 2010.

  1. #1
    Hi,

    On one of my databases I'm trying to create a constraint check for to check that a string has two digits followed by two characters, Could anyone provide me with an example of how I could go about doing this?

    So far I've tried the following but neither work:

    
    CONSTRAINT chk_id CHECK (id LIKE '[0-9][a-zA-Z][a-zA-Z]')
    
    CONSTRAINT chk_id CHECK (id LIKE '[0-9][a-z,A-Z][a-z,A-Z]')
    
    Code (markup):

     
    Last edited: Feb 5, 2010
    Silver89, Feb 5, 2010 IP
  2. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #2
    After a long time searching I found the answer so here it is for future reference:

    
    CONSTRAINT chk_id CHECK ( REGEXP_LIKE ( id, '[0-9][a-zA-Z][a-zA-Z]') )
    
    Code (markup):
     
    Silver89, Feb 5, 2010 IP