Home » SQL & PL/SQL » SQL & PL/SQL » how to impose the check constraint (Oracle, 10g, windows XP)
how to impose the check constraint [message #359669] Mon, 17 November 2008 23:33 Go to next message
jyothsna1612
Messages: 68
Registered: June 2008
Member
Hi
I need to impose the constraint for the following table with the following conditions

Tables are:

Classes(class, type, country, numguns, bore, displacement)
Battles(name, date)
Outcomes(ship, battle, result)
Ships(name, class, launched)


And the constraint is :
If a class of ships has more than 9 guns, then their bore must be no larger than 14 inches.

So just need the hint how to use the check constraint for the above 2 conditions...
Re: how to impose the check constraint [message #359676 is a reply to message #359669] Tue, 18 November 2008 00:04 Go to previous messageGo to next message
jyothsna1612
Messages: 68
Registered: June 2008
Member
Hi,

No response till now...
Means Cann't we impose the check constraint on this....
Re: how to impose the check constraint [message #359700 is a reply to message #359676] Tue, 18 November 2008 00:56 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
I didn't even read your post seeing your add-on.
You posted this at 6AM for me.
All USA East-cost and most Europeans are sleeping.
This is a free forum. Don't complain after half an hour.
Patiently wait or pay for a professional.

In the meantime, read OraFAQ Forum Guide and search on this forum, I bet there already is the answer.

Regards
Michel
Re: how to impose the check constraint [message #359772 is a reply to message #359700] Tue, 18 November 2008 02:49 Go to previous message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
This example should get you moving:
create table test_021 (col_1  number, col_2 number);

-- Constraint: If col_1 >0 then col_2 must be > 0

alter table test_021 add constraint test_021_ck1 check(case when col_1 <=0 then 0 
                                                            when col_1 >0  and col_2 > 0 then 0 
                                                            else 1 end = 0);

insert into test_021 values (0,0);
insert into test_021 values (1,1);
insert into test_021 values (1,0);
Previous Topic: use varchar2 value as cursor elements ..
Next Topic: Sql Query
Goto Forum:
  


Current Time: Sun Dec 04 15:06:26 CST 2016

Total time taken to generate the page: 0.07964 seconds