Friday 6 September 2013

What are constraints?


Constraints enforce rules on the tables.  Constraints prevent deletion of a table, if there are dependencies.  Oracle uses constraints to prevent invalid data entry into tables. [Updates and inserts].  The constraints applied must be satisfied for the successful operation.  The constraints are called integrity constraints  (i.e., to maintain security and integrity this means honesty and reliability) of the database.  An integrity constraint is a mechanism used by oracle to prevent invalid data entry into the table and inadvertent deletes.  So constraints enforce rules that the columns in a table have to confirm with.  The various types of Integrity constraints are:
  • Domain Integrity Constraints
Not null Constraint

Check Constraint

  • Entity Integrity Constraints
Unique Constraint

Primary Key


  • Referential Integrity Constraints
Foreign Key




Wednesday 20 March 2013

Why PL/SQL Exceptions Exceptions?

Using exceptions for error handling has several advantages. Without exception handling, every time you issue a command, you must check for execution errors:

BEGIN
   SELECT ...
      -- check for 'no data found' error
   SELECT ...
      -- check for 'no data found' error
   SELECT ...
      -- check for 'no data found' error

Error processing is not clearly separated from normal processing; nor is it robust. If you neglect to code a check, the error goes undetected and is likely to cause other, seemingly unrelated errors.
With exceptions, you can handle errors conveniently without the need to code multiple checks, as follows:

BEGIN
   SELECT ...
   SELECT ...
   SELECT ...
   ...
EXCEPTION
   WHEN NO_DATA_FOUND THEN  -- catches all 'no data found' errors
Exceptions improve readability by letting you isolate error-handling routines. Exceptions also improve reliability. You need not worry about checking for an error at every point it might occur. Just add an exception handler to your PL/SQL block. If the exception is ever raised in that block (or any sub-block), you can be sure it will be handled.