Jump to content

Check Constraint SQL


mikhl

Recommended Posts

I want to create a check constraint that allows the input of data like 'COMP%' and 'SYS%' and 'INFO%'

 

The code that I have tried is as follows:

alter table subject
add constraint validclassid check(subjectid like 'COMP%', 'INFO%', 'SYS%');

and...

alter table subject
add constraint validclassid check(subjectid like 'COMP%' AND 'INFO%' AND 'SYS%');

and...

alter table subject
add constraint validclassid check(subjectid like 'COMP%' OR 'INFO%' OR 'SYS%');

 

None of the above are working, I could really use your help. Thanks.

 

I am using Oracle 10g

Link to comment
Share on other sites

A check constraint is like a little piece of validation code, that must evaluation to true or false.  It is not a query.  I'm not really sure what you're going for, but if you literally expect that the subjectid will be the strings 'COMP%' or 'INFO%', then you should have add ... check( subjectid in ('COMP%', 'INFO%', 'SYS%'))

 

If you literally are trying to get "LIKE" behavior so that you only allow words that start with COMP, INFO and SYS, but are actually COMPUTER, INFORMATION etc., then you might try using SUBSTR() to get the first 3 characters, although I don't know if that will work in a constraint.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.