schwartz8a
asked on
How can I perform a select in an check constraint?
Hi,
I'd like to do the following:
ALTER TABLE local_sale_terms
ADD CONSTRAINT constr_check_cancelled
CHECK (NOT EXISTS (SELECT 1
FROM local_sale_terms
WHERE cancelled='N'
GROUP BY parent_no,date_of_term,can celled
HAVING COUNT(*)>1))
But Oracle complains about a query in the constraint.
How can i enforce having only ONE Uncancelled row?
I can have many cancelled rows, but only one uncancelled row.
a unique index on (parent_no,date_of_term,ca ncelled) is therefore inappropriate.
help
thanks
adam
I'd like to do the following:
ALTER TABLE local_sale_terms
ADD CONSTRAINT constr_check_cancelled
CHECK (NOT EXISTS (SELECT 1
FROM local_sale_terms
WHERE cancelled='N'
GROUP BY parent_no,date_of_term,can
HAVING COUNT(*)>1))
But Oracle complains about a query in the constraint.
How can i enforce having only ONE Uncancelled row?
I can have many cancelled rows, but only one uncancelled row.
a unique index on (parent_no,date_of_term,ca
help
thanks
adam
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
schwartz8a,
What you say is right... As per the SQL standards SQL queries are allowed in check constraint, but I dont think that it is possible in oracle.
William.
What you say is right... As per the SQL standards SQL queries are allowed in check constraint, but I dont think that it is possible in oracle.
William.
ASKER
I know i can use triggers.
But Joe Celko's book, SQL for Smarties, says that queries within check constraints are preferable to triggers. He even gives an example similar to the one i posted.
any other ideas?