PDA

View Full Version : Conditional Constraint?


DA Morgan
12-23-2002, 12:25 AM
wing wrote:
Hi, I am new in Oracle and have a query on how to add conditional constraint. Say, I have a simple table Demerit with three fields. Demerit(DEM_CODE, DEM_DES, POINTS) where DEM_CODE (N, 2) DEM_DES (C, 30) POINTS (N, 1) How to add the following constraint? All DEM_CODE should carry an integer POINT between 1 to 6 inclusive, and DEM_CODE greater than 20 should carry no more than 3 POINT. Thanks in advance of any ideas and inputs. Wing

What you are trying to do requires a trigger. I would suggest a
BEFORE INSERT AND UPDATE trigger that fires for each row.

I would also suggest that in the future you:
1. List your version and edition of Oracle
2. NEVER EVER post to more than a single usenet group unless you are
trying to get people so angry they won't help you.

Daniel Morgan

J Alex
12-23-2002, 04:44 AM
"DA Morgan" <damorgan@exesolutions.com> wrote wing wrote: Hi, I am new in Oracle and have a query on how to add conditional constraint. Say, I have a simple table Demerit with three fields. Demerit(DEM_CODE, DEM_DES, POINTS) where DEM_CODE (N, 2) DEM_DES (C, 30) POINTS (N, 1) How to add the following constraint? All DEM_CODE should carry an integer POINT between 1 to 6 inclusive, and DEM_CODE greater than 20 should carry no more than 3 POINT. Thanks in advance of any ideas and inputs. Wing What you are trying to do requires a trigger.

No, it doesn't. Check constraints work well for this sort of thing. Note
Jonathon Lewis' post with the constraint.

DA Morgan
12-23-2002, 02:33 PM
J Alex wrote:
"DA Morgan" <damorgan@exesolutions.com> wrote wing wrote: Hi, I am new in Oracle and have a query on how to add conditional constraint. Say, I have a simple table Demerit with three fields. Demerit(DEM_CODE, DEM_DES, POINTS) where DEM_CODE (N, 2) DEM_DES (C, 30) POINTS (N, 1) How to add the following constraint? All DEM_CODE should carry an integer POINT between 1 to 6 inclusive, and DEM_CODE greater than 20 should carry no more than 3 POINT. Thanks in advance of any ideas and inputs. Wing What you are trying to do requires a trigger. No, it doesn't. Check constraints work well for this sort of thing. Note Jonathon Lewis' post with the constraint.

I missed Jonathan's posting but the request was for:

"All DEM_CODE should carry an integer POINT"

I'd like to see a Check Constraint with an "AND" clause.

Daniel Morgan


MyLounge.com Site Map
Forum: Cars, Cell Phone, Database, Games, Home Improvement, IT, Music, School, Sports, Web Design, Web Server, Weight Loss

The MyLounge.com forum is intended for informational use only and should not be relied upon and is not a substitute for any advice. The information contained on MyLounge.com are opinions and suggestions of members and is not a representation of the opinions of MyLounge.com. MyLounge.com does not warrant or vouch for the accuracy, completeness or usefulness of any postings or the qualifications of any person responding. Please consult a expert or seek the services of an attorney in your area for more accuracy on your specific situation. Please note that our forums also serve as mirrors to Usenet newsgroups. Many posts you see on our forums are made by newsgroup users who may not be members of MyLounge.com Term of Service