473,382 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

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
2 4784
ck9663
2,878 Expert 2GB
Could be because your sql server is configured to ignore cases.

Good Luck!!!


~~ CK
Sep 17 '12 #2
Rabbit
12,516 Expert Mod 8TB
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

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

Similar topics

3
by: Hari Om | last post by:
Hi ORAPERTS (ORAcle xPERTS) How can I define a CHECK CONSTRAINT on a table for a field like zip code....? Here is what I am doing: create table test ( state varchar2(5) check (state...
2
by: Doug Baroter | last post by:
Hi, DDLs and DMLs: create table #job (jobID int identity(1,1) primary key, jobName varchar(25) unique not null, jobEndDate dateTime, jobComplete bit default(0), check (( is null and = 0) OR (...
0
by: Fabre Lambeau | last post by:
I've got a problem when adding a CONSTRAINT CHECK on a table by calling a function. It just seems not to work... Here is the table (simplified to only the relevant fields for this case): ...
1
by: Jagdip Singh | last post by:
Hi all, I have four tables create table employee (emp_num integer not null, emp_name varchar(20), emp_commision real, emp_salary real );
2
by: kaming | last post by:
Dear all, Is it possible to define a check constraint on a field that the field value must exist in another table non-unique field? how to write the create table DDL? i.e TABLE A TYPE,...
3
by: ferg | last post by:
I have a Customer table. The table has two different CHECK constraints. Then there is the Customer details dialog, which provides the user with an UI for changing users. I have some UPDATE sql,...
1
by: jecaruthersjr | last post by:
I am attempting to write a Check Constraint on an MSSQL2k server that will only allow a string to be INSERTED or UPDATED if it is formatted correctly. The correct format being, that the first...
1
by: Spectre1337 | last post by:
Hello, it seems like the check constraint validation of MS SQL Server Management Studio express is horribly, horribly broken. Either that or I'm using it wrong. I hope it's the latter. I'm...
3
by: Helen Wheels | last post by:
Can we use parentheses in a check constraint in MS-SQL-server DDL? e.g. I'm having a problem with the following statement: ALTER TABLE . ADD CONSTRAINT CHECK (( IS NULL AND IS NULL) OR (...
2
by: joerg.sailer | last post by:
Hello, is it possible to define a CHECK CONSTRAINT on a table, whereas the CHECK-OPTION will be a SELECT. With this CHECK CONSTRAINT i try to ensure, that there will allways a state only set once...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.