By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,714 Members | 1,195 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,714 IT Pros & Developers. It's quick & easy.

How to write check constraint to check for uppercase character and digit?

P: 1
I want to write a check constraint in SQL Server to check that the ID is exactly 5 characters long, starts and ends with an UPPER case an there are 3 digit in between. Do I use a LIKE clause? Or how?

I tried using
CONSTRAINT ValidID CHECK (clientID LIKE '[A-Z][0-9][0-9][0-9][A-Z]')

But if I do this, and I insert a id 'a123e' (starting and ending with small capital letter, it will still let me go through. By right, it should forbid me to do so.
Sep 17 '12 #1
Share this Question
Share on Google+
2 Replies

Expert 2.5K+
P: 2,878
Could be because your sql server is configured to ignore cases.

Good Luck!!!

~~ CK
Sep 17 '12 #2

Expert Mod 10K+
P: 12,430
ck is correct, by default, SQL Server will ignore case. Change the collation of the column to Latin1_General_CS_AS. That will make it case sensitive.
Sep 17 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.