July 22, 2008 at 5:12 pm
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.
July 23, 2008 at 1:34 pm
Try this ,
Name like ('^[A-Z]+[a-z]*$')
July 23, 2008 at 7:43 pm
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...
July 24, 2008 at 11:49 am
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?
July 27, 2008 at 2:29 am
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