| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: check constraint question - still perplexed
Solved
Qualifying the ambiguous column in the check constraint fixes things. Thus
> create table DEPRECIATION
> (
> ASSETID char(6) not null,
> DEPRECIATIONDATE date not null,
> DEPRECIABLEAMOUNT numeric(8,2) not null,
> check (NOT EXISTS (select a.assetID
> from asset as a, assetClass as b
> where Depreciation.AssetID = a.AssetID and
> a.assetClass = b.AssetClass and
> depreciationDate >= dateadd(year, b.usefulLife, a.dateOfPurchase) ))
> );
Considering the biz Rule
Accumulated depreciation of an asset must be less than or equal to diffrence
between cost and residual value of that asset
yields
create table DEPRECIATION
(
ASSETID char(6) not null,
DEPRECIATIONDATE date not null,
DEPRECIABLEAMOUNT numeric(8,2) not null,
check (not exists(select a.assetID from
depreciation as a,asset as b where
![]() |
![]() |