Home > Ask the Oracle Database / Applications Experts > Questions & Answers > Assertions
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Assertions

Rudy Limeback EXPERT RESPONSE FROM: Rudy Limeback

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site
>
QUESTION POSED ON: 07 October 2004
I have two tables, one called nurses and the other called pharmacist. Both tables record their license number. I need to write an assertion that ensures that all licenses of nurses and pharmacists have been renewed in the last two years. Thank you for your help.

>

Congratulations, you've stumped me. Actually, this happens quite frequently, but usually because a question is submitted to Ask the Expert with insufficient information, or phrased ambiguously.

In this case, however, there's no ambiguity. The problem is quite clear. I just don't know the answer.

An assertion is a statement in SQL that ensures a certain condition will always exist in the database. Assertions are like column and table constraints, except that they are specified separately from table definitions. An example of a column constraint is NOT NULL, and an example of a table constraint is a compound foreign key, which, because it's compound, cannot be declared with column constraints.

An example of an assertion is:

create assertion recent_licenses
 check (
   ( select count(*) 
       from nurses
      where license_renewal_date 
          < '2002-01-01' ) = 0
       )

Now here's the problem. How could we specify an assertion that refers to "the last two years"? Certainly, we could try using the CURRENT_DATE keyword, as well as INTERVAL arithmetic to establish a date two years in the past. We might even be successful in declaring the assertion. (Not all database systems support assertions.)

However, assertions are checked only when UPDATE or INSERT actions are performed against the table. So we can postulate a situation where the assertion has been defined, all the nurses are licensed within the last two years, and then no changes are made against the table for three years. The assertion would be violated!

Besides, you may have difficulty composing the assertion in a manner that will even be accepted by your database system. You will likely save yourself a lot of heartache and effort if you simply set up a periodic scheduled task or cron job to run a query and report on any licenses that have expired.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Oracle White Papers: Fusion Middleware
HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2003 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts