3

Im using SQL/PL developer and I have a table named Appeal, that has 2 attributs OpenDate and CloseDate. And I want to add a constraint to ensure that open date will be smaller than close date. I have a lot of records in this table.

this is my code:

alter table appeal
add constraint Check_Dates
check (OpenDate < CloseDate)

and I get en error saying: ORA-02293: cannot validate (STSTEM.CHECK_DATES) - check constraint violated

any ieads? Thanx

2 Answers 2

6

Your constraint looks right, I have tested it:

create table appeal ( OpenDate date,  CloseDate date);

alter table appeal
add constraint Check_Dates
check (OpenDate < CloseDate);

insert into appeal values ( sysdate, sysdate - 1 );

And here the result:

Schema Creation Failed: ORA-02290: check constraint (USER_4_44096.CHECK_DATES) violated

Problem is than you have already rows with OpenDate < CloseDate values in your database. Fix it before create constraint. Look behavior changing sentences order:

create table appeal ( OpenDate date,  CloseDate date);

insert into appeal values ( sysdate, sysdate - 1 );

alter table appeal
add constraint Check_Dates
check (OpenDate < CloseDate);

And here your issue:

Schema Creation Failed: ORA-02293: cannot validate (USER_4_E4450.CHECK_DATES) - check constraint violated

Sign up to request clarification or add additional context in comments.

2 Comments

I see... But I already have data in the table that I inserted before that constrain was added, so could that be the problem?
Yes, this is the problem. Explained now on answer.
0

Try this alter table appeal add constraint Check_Dates check (OpenDate < CloseDate) ENABLE NOVALIDATE;

You will have check the previous data for errors but any new Data will fall under the CHECK

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.