Constraint

  • I am trying to place a constraint on one column of the following table:

    create table test

    (

    name varchar(20) no null

    )

    I would like to place a constraint on this column that only allows the characters A-Z in the first character and a-z in all others. I know how to do the first character but I would like to know the syntax to then allow from 1 to 19 characters in the a-z range. I've tried this:

    name like ('[A-Z][a-z]{1,19}')

    SQL Server accepts that syntax but does not seem to work correctly. I'm no Regular Expression guru but thought this should work.

    Thanks for any help.

  • Try this ,

    Name like ('^[A-Z]+[a-z]*$')

  • Thanks!

    Can you help me understand this syntax. I don't see anything here that limits the input to 20 characters, one capital charcter and then up to 19 lowercase characters.

    Thanks again...

  • I guess I'm being stupid or something but I can't get anything like this to work. I simplified it to this:

    Name like '^[A-Z]'

    and then did the following insert,

    insert into table (name) values ('A');

    That simple command fails due to the constraint.

    What am I doing wrong?

  • with little bit eager, I wish to ask one question,

    How you applied this contraint on the column, Whether you have used check constraint,

    name like ('[A-Z][a-z]{1,19}')

    Please mail it to venkatesanj@hcl.in

    Thanks and Regards,
    Venkatesan Prabu, 😛
    My Blog:

    http://venkattechnicalblog.blogspot.com/

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply