Sunday 4 December 2011

Database ( 86 - 107 ) by www.yuvajobs.com



How are exceptions handled in PL/SQL? Give some of the internal exceptions' name
PL/SQL exception handling is a mechanism for dealing with run-time errors encountered during procedure execution. Use of this mechanism enables execution to continue if the error is not severe enough to cause procedure termination.
The exception handler must be defined within a subprogram specification. Errors cause the program to raise an exception with a transfer of control to the exception-handler block. After the exception handler executes, control returns to the block in which the handler was defined. If there are no more executable statements in the block, control returns to the caller.
User-Defined Exceptions
PL/SQL enables the user to define exception handlers in the declarations area of subprogram specifications. User accomplishes this by naming an exception as in the following example:
ot_failure  EXCEPTION;
In this case, the exception name is ot_failure. Code associated with this handler is written in the EXCEPTION specification area as follows:
EXCEPTION
when OT_FAILURE then
out_status_code := g_out_status_code;
out_msg         := g_out_msg;
The following is an example of a subprogram exception:
EXCEPTION
when NO_DATA_FOUND then
g_out_status_code := 'FAIL';
RAISE ot_failure;
Within this exception is the RAISE statement that transfers control back to the ot_failure exception handler. This technique of raising the exception is used to invoke all user-defined exceptions.
System-Defined Exceptions
Exceptions internal to PL/SQL are raised automatically upon error. NO_DATA_FOUND is a system-defined exception. Table below gives a complete list of internal exceptions.

PL/SQL internal exceptions.

Exception Name
Oracle Error
CURSOR_ALREADY_OPEN
ORA-06511
DUP_VAL_ON_INDEX
ORA-00001
INVALID_CURSOR
ORA-01001
INVALID_NUMBER
ORA-01722
LOGIN_DENIED
ORA-01017
NO_DATA_FOUND
ORA-01403
NOT_LOGGED_ON
ORA-01012
PROGRAM_ERROR
ORA-06501
STORAGE_ERROR
ORA-06500
TIMEOUT_ON_RESOURCE
ORA-00051
TOO_MANY_ROWS
ORA-01422
TRANSACTION_BACKED_OUT
ORA-00061
VALUE_ERROR
ORA-06502
ZERO_DIVIDE
ORA-01476

In addition to this list of exceptions, there is a catch-all exception named OTHERS that traps all errors for which specific error handling has not been established.

Does PL/SQL support "overloading"? Explain
The concept of overloading in PL/SQL relates to the idea that you can define procedures and functions with the same name. PL/SQL does not look only at the referenced name, however, to resolve a procedure or function call. The count and data types of formal parameters are also considered.
PL/SQL also attempts to resolve any procedure or function calls in locally defined packages before looking at globally defined packages or internal functions. To further ensure calling the proper procedure, you can use the dot notation. Prefacing a procedure or function name with the package name fully qualifies any procedure or function reference.

Tables derived from the ERD
Are totally unnormalised
Are always in 1NF
Can be further denormalised
May have multi-valued attributes

(b) Are always in 1NF

Spurious tuples may occur due to
Bad normalization 
Theta joins
Updating tables from join
a) i & ii                              b) ii & iii
c) i & iii                             d) ii & iii

i & iii  because  theta joins are joins made on keys that are not primary keys.

A B C is a set of attributes. The functional dependency is as follows
AB  ->   B
AC ->    C
C ->    B
is in 1NF
is in 2NF
is in 3NF
is in BCNF

 (a) is in 1NF since (AC)+ = { A, B, C} hence AC is the primary key. Since         C       B is a FD given, where neither C is a Key nor B is a prime attribute, this it is not in 3NF. Further B is not functionally dependent on key AC thus it is not in 2NF.  Thus the given FDs is in 1NF.

In mapping of ERD to DFD
entities in ERD should correspond to an existing entity/store in DFD
entity in DFD is converted to attributes of an entity in ERD
relations in ERD has 1 to 1 correspondence to processes in DFD
relationships in ERD has 1 to 1 correspondence to flows in DFD

entities in ERD should correspond to an existing entity/store in DFD

A dominant entity is the entity
on the N side in a 1 : N relationship
on the 1 side in a 1 : N relationship
on either side in a 1 : 1 relationship
nothing to do with 1 : 1 or 1 : N relationship

on the 1 side in a 1 : N relationship

Select  'NORTH', CUSTOMER From CUST_DTLS Where REGION = 'N' Order By
CUSTOMER Union Select  'EAST', CUSTOMER From CUST_DTLS Where REGION = 'E' Order By CUSTOMER
The above is
Not an error
Error - the string in single quotes 'NORTH' and 'SOUTH'
Error - the string should be in double quotes
Error -  ORDER BY clause

Error - the ORDER BY clause. Since ORDER BY clause cannot be used in UNIONS

What is Storage Manager? 
It is a program module that provides the interface between the low-level data stored in database, application programs and queries submitted to the system.   

What is Buffer Manager?
It is a program module, which is responsible for fetching data from disk storage into main memory and deciding what data to be cache in memory. 

What is Transaction Manager?
It is a program module, which ensures that database, remains in a consistent state despite system failures and concurrent transaction execution proceeds without conflicting.

What is File Manager?
It is a program module, which manages the allocation of space on disk storage and data structure used to represent information stored on a disk.  

What is Authorization and Integrity manager?
It is the program module, which tests for the satisfaction of integrity constraint and checks the authority of user to access data.   

What are stand-alone procedures?
Procedures that are not part of a package are known as stand-alone because they independently defined. A good example of a stand-alone procedure is one written in a SQL*Forms application. These types of procedures are not available for reference from other Oracle tools. Another limitation of stand-alone procedures is that they are compiled at run time, which slows execution.

What are cursors give different types of cursors.
PL/SQL uses cursors for all database information accesses statements. The language supports the use two types of cursors
Implicit
Explicit

What is cold backup and hot backup (in case of Oracle)?
Cold Backup:
It is copying the three sets of files (database files, redo logs, and control file) when the instance is shut down. This is a straight file copy, usually from the disk directly to tape. You must shut down the instance to guarantee a consistent copy.
If a cold backup is performed, the only option available in the event of data file loss is restoring all the files from the latest backup. All work performed on the database since the last backup is lost.
Hot Backup:
Some sites (such as worldwide airline reservations systems) cannot shut down the database while making a backup copy of the files. The cold backup is not an available option.
So different means of backing up database must be used — the hot backup. Issue a SQL command to indicate to Oracle, on a tablespace-by-tablespace basis, that the files of the tablespace are to backed up. The users can continue to make full use of the files, including making changes to the data. Once the user has indicated that he/she wants to back up the tablespace files, he/she can use the operating system to copy those files to the desired backup destination.
The database must be running in ARCHIVELOG mode for the hot backup option.
If a data loss failure does occur, the lost database files can be restored using the hot backup and the online and offline redo logs created since the backup was done. The database is restored to the most consistent state without any loss of committed transactions.

What are Armstrong rules? How do we say that they are complete and/or sound
The well-known inference rules for FDs        
Reflexive rule : 
                                          If Y is subset or equal to X then X       Y.
Augmentation rule:
                              If X       Y then XZ       YZ.
Transitive rule:
                              If  {X      Y, Y       Z} then X        Z.
Decomposition rule :
                                          If X       YZ then X       Y.
Union or Additive rule:
                                          If {X      Y, X        Z} then X       YZ.
Pseudo Transitive rule :
                                          If {X      Y, WY         Z} then WX        Z.
Of these the first three are known as Amstrong Rules. They are sound because it is enough if a set of FDs satisfy these three. They are called complete because using these three rules we can generate the rest all inference rules.

How can you find the minimal key of relational schema?
Minimal key is one which can identify each tuple of the given relation schema uniquely. For finding the minimal key it is required to find the closure that is the set of all attributes that are dependent on any given set of attributes under the given set of functional dependency.
Algo. I Determining X+, closure for X, given set of FDs F
Set X+ = X
Set Old X+ = X+
For each FD  Y        Z in F and if  Y belongs to X+ then add Z to X+
Repeat steps 2 and 3 until Old X+  = X+

Algo.II Determining minimal K for relation schema R, given set of FDs F
Set K to R that is make K a set of all attributes in R
For each attribute A in K
Compute (K – A)+ with respect to F
If  (K – A)+ = R then set K = (K – A)+


What do you understand by dependency preservation?
Given a relation R and a set of FDs F, dependency preservation states that the closure of  the union of the projection of F on each decomposed relation Ri is equal to the closure of F. i.e.,
((PR1(F))  U … U (PRn(F)))+ =  F+
if decomposition is not dependency preserving, then some dependency is lost in the decomposition.

What is meant by Proactive, Retroactive and Simultaneous Update.
Proactive Update:
The updates that are applied to database before it becomes effective in real world .
Retroactive Update:
The updates that are applied to database after it becomes effective in real world .
Simulatneous Update:
The updates that are applied to database at the same time when it becomes effective in real world .

What are the different types of JOIN operations?
Equi Join:  This is the most common type of join which involves only equality comparisions. The disadvantage in this type of join is that there