You are on page 1of 58

Oracle DBA Q&A:

Part 1:
1.1 Q- Which are the default passwords of SYSTEM/SYS? A- MANAGER / CHANGE_ON_INSTALL 1.2 Q- How can you execute a script file in SQLPLUS? A- To execute a script file in SQLPlus, type @ and then the file name. 1.3 Q- Where can you find official Oracle documentation? A- tahiti.oracle.com 1.4 Q- What is the address of the Official Oracle Support? A- metalink.oracle.com or support.oracle.com 1.5 Q- What file will you use to establish Oracle connections from a remote client? A- tnsnames.ora 1.6 Q- How can you check if the database is accepting connections? A- lsnrctl status or lsnrctl services 1.7 Q- Which log would you check if a database has a problem? A- Alert log 1.8 Q- Name three clients to connect with Oracle, for example, SQL Developer: A- SQL Developer, SQL-Plus, TOAD, dbvisualizer, PL/SQL Developer There are several, but an experienced dba should know at least three clients. 1.9 Q- How can you check the structure of a table from sqlplus? A- DESCRIBE or DESC 1.10 Q- What command will you start to run the installation of Oracle software on Linux? A- runInstaller 2.1 Q- What should you do if you encounter an ORA-600? A- Contact Oracle Support 2.2 Q- Explain the differences between PFILE and SPFILE A- A PFILE is a Static, text file that initializes the database parameter in the moment that its started. If you want to modify parameters in PFILE, you have to restart the database. A SPFILE is a dynamic, binary file that allows you to overwrite parameters while the database is already started (with some exceptions) 2.3 Q- In which Oracle version was Data Pump introduced? A- Oracle 10g 2.4 Q- Say two examples of DML, two of DCL and two of DDL A- DML: SELECT, INSERT, UPDATE, DELETE, MERGE, CALL, EXPLAIN PLAN, LOCK TABLE DDL: CREATE, ALTER, DROP, TRUNCATE, COMMENT, RENAME DCL: GRANT, REVOKE
Prepared by: Nasser

1|Page

2.5 Q- You want to save the output of an Oracle script from sqlplus. How would you do it? A- spool script_name.txt select * from your_oracle_operations; spool off; 2.6 Q- What is the most important requirement in order to use RMAN to make consistent hot backups? A- Your database has to be in ARCHIVELOG mode. 2.7 Q- Can you connect to a local database without a listener? A- Yes, you can. 2.8 Q- In which view can you find information about every view and table of oracle dictionary? A- DICT or DICTIONARY 2.9 Q- How can you view all the users account in the database? A- SELECT USERNAME FROM DBA_USERS; 2.10 Q- In linux, how can we change which databases are started during a reboot? A- Edit /etc/oratab 3.1 Q- When a user process fails, what Oracle background process will clean after it? A- PMON 3.2 Q- How can you reduce the space of TEMP datafile? A- Prior to Oracle 11g, you had to recreate the datafile. In Oracle 11g a new feature was introduced and you can shrink the TEMP tablespace. 3.3 Q- How can you view all the current users connected in your database in this moment? A- SELECT COUNT(*),USERNAME FROM V$SESSION GROUP BY USERNAME; 3.4 Q- Explain the differences between SHUTDOWN, SHUTDOWN NORMAL, SHUTDOWN IMMEDIATE AND SHUTDOWN ABORT. A- SHUTOWN NORMAL = SHUTDOWN : It waits for all sessions to end, without allowing new connections. SHUTDOWN IMMEDIATE : Rollback current transactions and terminates every session. SHUTDOWN ABORT : Aborts all the sessions, leaving the database in an inconsistent state. Its the fastest method, but can lead to database corruption. 3.5 Q- Is it possible to backup your database without the use of an RMAN database to store the catalog? A- Yes, but the catalog would be stored in the controlfile. 3.6 Q- Which are the main components of Oracle Grid Control? A- OMR (Oracle Management Repository), OMS (Oracle Management Server) and OMA (Oracle Management Agent). 3.7 Q- What command will you use to navigate through ASM files? A- asmcmd 3.8 Q- What is the difference between a view and a materialized view? A- A view is a select that is executed each time an user accesses to it. A materialized view stores the result of this query in memory for faster access purposes. 3.9 Q- Which one is faster: DELETE or TRUNCATE? A- TRUNCATE
Prepared by: Nasser

2|Page

3.10 Q- Are passwords in oracle case sensitive? A- Only since Oracle 11g. 4.1 Q- What is the recommended method to make backups of a RAC environment? A- RMAN to make backups of the database, dd to backup your voting disk and hard copies of the OCR file. 4.2 Q- What command would you use to check the availability of the RAC system? A- crs_stat -t -v (-t -v are optional) 4.3 Q- What is the minimum number of instances you need to have in order to create a RAC? A- 1. You can create a RAC with just one server. 4.4 Q- Name two specific RAC background processes A- RAC processes are: LMON, LMDx, LMSn, LKCx and DIAG. 4.5 Q- Can you have many database versions in the same RAC? A- Yes, but Clusterware version must be greater than the greater database version. 4.6 Q- What was RAC previous name before it was called RAC? A- OPS: Oracle Parallel Server 4.7 Q- What RAC component is used for communication between instances? A- Private Interconnect. 4.8 Q- What is the difference between normal views and RAC views? A- RAC views has the prefix G. For example, GV$SESSION instead of V$SESSION 4.9 Q- Which command will we use to manage (stop, start) RAC services in command -line mode? A- srvctl 4.10 Q- How many alert logs exist in a RAC environment? A- One for each instance. 5.1 Q- How can you difference a usual parameter and an undocumented parameter? A- Undocumented parameters have the prefix _. For example, _allow_resetlogs_corruption 5.2 Q- What is BBED? A- An undocumented Oracle tool used for foresnic purposes. Stans for Block Browser and EDitor. 5.3 Q- The result of the logical comparison (NULL = NULL) will be And in the case of (NULL != NULL) A- False in both cases. 5.4 Q- Explain Oracle memory structure The Oracle RDBMS creates and uses storage on the computer hard disk and in random access memory (RAM). The portion in the computer s RAM is called memory structure. Oracle has two memory structures in the computer s RAM. The two structures are the Program Global Area (PGA) and the System Global Area (SGA). The PGA contains data and control information for a single user process. The SGA is the memory segment that stores data that the user has retrieved from the database or data that the user wants to place into the database. 5.5 Q- Will RMAN takes backups of read-only tablespaces? A- No

Prepared by: Nasser

3|Page

5.6 Q- Will a user be able to modify a table with SELECT only privilege? A- He wont be able to UPDATE/INSERT into that table, but for some reason, he will still be able t o lock a certain table. 5.7 Q- What Oracle tool will you use to transform datafiles into text files? A- Trick question: you cant do that, at least with any Oracle tool. A very experienced DBA should perfectly know this.
5.8 Q- SQL> SELECT * FROM MY_SCHEMA.MY_TABLE;

SP2-0678: Column or attribute type cannot be displayed by SQL*Plus Why Im getting this error? A- The table has a BLOB column. 5.9 Q- What parameter will you use to force the starting of your database with a corrupted resetlog? A- _ALLOW_RESETLOGS_CORRUPTION 5.10 Q- Name the seven types of Oracle tables A- Heap Organized Tables, Index Organized Tables, Index Clustered Tables, Hash Clustered Tables, Nested Tables, Global Temporary Tables, Object Tables.

Prepared by: Nasser

4|Page

Part 2:
1.What is an Oracle Instance? An Oracle database server consists of an Oracle database and an Oracle instance. Every time a database is started, a system global area (SGA) is allocated and Oracle background processes are started. The combination of the background processes and memory buffers is called an Oracle instance. We can run multiple instances on the same Oracle Database Server, where each instance connects to its database. Oracle instance includes: SGA - System or Shared Global Area Components of SGA: DBBC - Database Buffer Cache SP - Shared Pool; divided into Library Cache (LC) and Data Dictionary Cache (DDC) or Row Cache. RLB - Redo Log Buffer Background Process (10/11g database): Mandatory Processes SMON - System Monitor PMON - Process Monitor DBWR - Database writer LGWR - Log Writer CKPT - Check point RECO - Recoverer DIAG - Diagnosability (new in 11g) VKTM - Virtual keeper of time (keeps "SGA Time" variable in current, new in 11g) Optional Process ARCN - Archiver MMAN - Memory Manager - ASMM MMON - Memory Monitor MMNL - Memory Monitor Light - AWR and few more... List of running processes of a single instance (11g) on Linux: [oracle@hostname ~]$ top -n 1 -U oracle -c
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 9181 oracle 15 0 745m 111m 109m S 6.9 7.5 1:11.15 ora_j000_DB1_SID 9163 oracle 16 0 745m 68m 65m S 5.3 4.6 0:11.95 ora_j001_DB1_SID 10420 oracle 18 0 744m 12m 11m R 3.0 0.8 0:00.09 ora_j002_DB1_SID 6773 oracle 16 0 748m 40m 34m S 0.7 2.7 0:03.16 ora_dbw0_DB1_SID 6775 oracle 16 0 759m 34m 33m S 0.7 2.4 0:10.74 ora_lgwr_DB1_SID 6767 oracle 15 0 744m 13m 11m S 0.3 0.9 0:02.17 ora_psp0_DB1_SID 6785 oracle 15 0 744m 19m 18m S 0.3 1.3 0:02.66 ora_mmnl_DB1_SID 6560 oracle 18 0 42048 9348 6788 S 0.0 0.6 0:00.86 tnslsnr LISTENER -inherit 6755 oracle 15 0 744m 16m 14m S 0.0 1.1 0:02.50 ora_pmon_DB1_SID 6757 oracle -2 0 744m 13m 11m S 0.0 0.9 0:04.31 ora_vktm_DB1_SID 6761 oracle 15 0 744m 13m 11m S 0.0 0.9 0:00.34 ora_gen0_DB1_SID 6763 oracle 18 0 744m 12m 11m S 0.0 0.9 0:00.53 ora_diag_DB1_SID 6765 oracle 15 0 744m 19m 18m S 0.0 1.3 0:00.59 ora_dbrm_DB1_SID 6769 oracle 18 0 744m 16m 14m S 0.0 1.1 0:07.11 ora_dia0_DB1_SID 6771 oracle 18 0 744m 17m 16m S 0.0 1.2 0:11.13 ora_mman_DB1_SID 6777 oracle 16 0 744m 16m 14m S 0.0 1.1 0:08.51 ora_ckpt_DB1_SID

Prepared by: Nasser

5|Page

6779 oracle 15 0 748m 87m 84m S 0.0 5.9 0:04.61 ora_smon_DB1_SID 6781 oracle 18 0 744m 18m 17m R 0.0 1.3 0:00.52 ora_reco_DB1_SID 6783 oracle 15 0 748m 56m 51m S 0.0 3.8 0:06.01 ora_mmon_DB1_SID 6787 oracle 15 0 744m 13m 11m S 0.0 0.9 0:00.35 ora_d000_DB1_SID 6789 oracle 15 0 744m 12m 11m S 0.0 0.8 0:00.31 ora_s000_DB1_SID 6852 oracle 18 0 744m 14m 13m S 0.0 1.0 0:00.40 ora_qmnc_DB1_SID 6859 oracle 15 0 744m 25m 23m S 0.0 1.7 0:00.53 ora_q000_DB1_SID 6864 oracle 18 0 744m 15m 14m S 0.0 1.0 0:00.21 ora_q001_DB1_SID 6983 oracle 15 0 748m 54m 48m S 0.0 3.7 0:05.40 ora_cjq0_DB1_SID 7141 oracle 15 0 744m 13m 12m S 0.0 0.9 0:00.26 ora_smco_DB1_SID 7722 oracle 16 0 753m 58m 55m S 0.0 4.0 0:07.64 oracleDB1_SID (LOCAL=NO) 10254 oracle 15 0 744m 14m 12m S 0.0 1.0 0:00.10 ora_w000_DB1_SID

2. What information is stored in Control File? Oracle Database must have at least one control file. It's a binary file contains some of the following information: The database name and unique ID The timestamp of database creation The names and locations of associated datafiles and redo log files Tablespace information Datafile offline ranges Archived log information and history Backup set and backup piece information Backup datafile and redo log information Datafile copy information Log records: sequence numbers, SCN range in each log RMAN Catalog Database block corruption information

The location of the control files is specified through the control_filesinitparam: SYS@DB1_SID SQL>show parameter control_file; NAME TYPE VALUE ------------------------------------ ----------- -----------------------------control_file_record_keep_time integer 7 control_files string /u01/app/oracle/oradata/DB1_SID /control01.ctl, /u01/app/oracl e/flash_recovery_area/DB1_SID/c ontrol02.ctl

3. When you start an Oracle DB which file is accessed first? Oracle first opens and reads the initialization parameter file (init.ora) [oracle@hostname ~]$ls -la $ORACLE_HOME/dbs/initDB1_SID.ora
-rw-r--r-- 1 oracle oinstall 1023 May 10 19:27 /u01/app/oracle/product/11.2.0/dbs/initDB1_SID.ora

4. What is the job of SMON and PMON processes? SMON - System Monitor Process - Performs recovery after instance failure, monitors temporary segments and extents; cleans temp segments, coalesces free space (mandatory process for DB and starts by default)

Prepared by: Nasser

6|Page

PMON - Process Monitor - Recovers failed process resources. In Shared Server architecture, monitors and restarts any failed dispatcher or server processes (mandatory process for DB and starts by default) [oracle@hostname ~]$ps -ef |grep -e pmon -e smon |grep -v grep
oracle 6755 1 0 12:59 ? 00:00:05 ora_pmon_DB1_SID oracle 6779 1 0 12:59 ? 00:00:06 ora_smon_DB1_SID

5. What is Instance Recovery? While Oracle instance fails, Oracle performs an Instance Recovery when the associated database is being restarted. Instance recovery occurs in two steps: Cache recovery: Changes being made to a database are recorded in the database buffer cache. These changes are also recorded in online redo log files simultaneously. When there are enough data in the database buffer cache,they are written to data files. If an Oracle instance fails before the data in the database buffer cache are written to data files, Oracle uses the data recorded in the online redo log files to recover the lost data when the associated database is re-started. This process is called cache recovery. Transaction recovery: When a transaction modifies data in a database, the before image of the modified data is stored in an undo segment. The data stored in the undo segment is used to restore the original values in case a transaction is rolled back. At the time of an instance failure, the database may have uncommitted transactions. It is possible that changes made by these uncommitted transactions have gotten saved in data files. To maintain read consistency, Oracle rolls back all uncommitted transactions when the associated database is restarted. Oracle uses the undo data stored in undo segments to accomplish this. This process is called transaction recovery. 6. What is being written into the Redo Log Files? Redo log records all changes made in datafiles. In the Oracle database, redo logs comprise files in a proprietary format which log a history of all changes made to the database. Each redo log file consists of redo records. A redo record, also called a redo entry, holds a group of change-vectors, each of which describes or represents a change made to a single block in the database. Let's get into this topic a little bit dipper: Log writer (LGWR) writes redo log buffer contents Into Redo Log FIles. LGWR does this every three seconds, when the redo log buffer is 1/3 full and immediately before the Database Writer (DBWn) writes its changed buffers into the datafile. The redo log of a database consists of two or more redo log files. The database requires a minimum of two files to guarantee that one is always available for writing while the other is being archived (if the DB is in ARCHIVELOG mode). LGWR writes to redo log files in a circular fashion. When the current redo log file fills, LGWR begins writing to the next available redo log file. When the last available redo log file is filled, LGWR returns to the first redo log file and writes to it, starting the cycle again. Filled redo log files are available to LGWR for reuse depending on whether archiving is enabled. If archiving is disabled (the database is in NOARCHIVELOG mode), a filled redo log file is available after the changes recorded in it have been written to the datafiles.

Prepared by: Nasser

7|Page

If archiving is enabled (the database is in ARCHIVELOG mode), a filled redo log file is available to LGWR after the changes recorded in it have been written to the datafiles and the file has been archived. Oracle Database uses only one redo log files at a time to store redo records written from the redo log buffer. The redo log file that LGWR is actively writing to is called the current redo log file. Redo log files that are required for instance recovery are called active redo log files. Redo log files that are no longer required for instance recovery are called inactive redo log files. If the database is in ARCHIVELOG mode it cannot reuse or overwrite an active online log file until one of the archiver background processes (ARCn) has archived its contents. If archiving is disabled (DB is in NOARCHIVELOG mode), then when the last redo log file is full, LGWR continues by overwriting the first available active file. A log switch is the point at which the database stops writing to one redo log file and begins writing to another. Normally, a log switch occurs when the current redo log file is completely filled and writing must continue to the next redo log file. However, you can configure log switches to occur at regular intervals, regardless of whether the current redo log file is completely filled. You can also force log switches manually. Oracle Database assigns each redo log file a new log sequence number every time a log switch occurs and LGWR begins writing to it. When the database archives redo log files, the archived log retains its log sequence number. 7. How do you control number of Datafiles one can have in an Oracle database? The db_files parameter is a "soft limit " parameter that controls the maximum number of physical OS files that can map to an Oracle instance. The maxdatafiles parameter is a different - "hard limit" parameter. When issuing a "create database" command, the value specified for maxdatafiles is stored in Oracle control files and default value is 32. The maximum number of database files can be set with the init parameter db_files. 8. How many Maximum Datafiles can there be in Oracle Database? Regardless of the setting of this paramter, maximum per database: 65533 (May be less on some operating systems) Maximum number of datafiles per tablespace: OS dependent = usually 1022 Limited also by size of database blocks and by the DB_FILES initialization parameter for a particular instance Bigfile tablespaces can contain only one file, but that file can have up to 4G blocks. 9. What is a Tablespace? A tablespace is a logical storage unit within an Oracle database. Tablespace is not visible in the file system of the machine on which the database resides. A tablespace, in turn, consists of at least one datafile which, in turn, are physically located in the file system of the server. A datafile belongs to exactly one tablespace. Each table, index and so on that is stored in an Oracle database belongs to a tablespace. The tablespace builds the bridge between the Oracle database and the filesystem in which the table's or index' data is stored. There are three types of tablespaces in Oracle: Permanent tablespaces Undo tablespaces Temporary tablespaces

Prepared by: Nasser

8|Page

10. What is the purpose of Redo Log files? Before Oracle changes data in a datafile it writes these changes to the redo log. If something happens to one of the datafiles, a backed up datafile can be restored and the redo, that was written since, replied, which brings the datafile to the state it had before it became unavailable. 11. Which default Database roles are created when you create a Database? CONNECT , RESOURCE and DBA are three default roles. The DBA_ROLES data dictionary view can be used to list all roles of a database and the authentication used for each role. The following query lists all the roles in the database:
SELECT * FROM DBA_ROLES; ROLE PASSWORD ---------------- -------CONNECT NO RESOURCE NO DBA NO SECURITY_ADMIN YES

12. What is a Checkpoint? A checkpoint occurs when the DBWR (database writer) process writes all modified buffers in the SGA buffer cache to the database data files. Data file headers are also updated with the latest checkpoint SCN, even if the file had no changed blocks. Checkpoints occur AFTER (not during) every redo log switch and also at intervals specified by initialization parameters. Set parameter LOG_CHECKPOINTS_TO_ALERT=TRUE to observe checkpoint start and end times in the database alert log. Checkpoints can be forced with the ALTER SYSTEM CHECKPOINT; command. SCN can refer to: System Change Number - A number, internal to Oracle that is incremented over time as change vectors are generated, applied, and written to the Redo log. System Commit Number - A number, internal to Oracle that is incremented with each database COMMIT. Note: System Commit Numbers and System Change Numbers share the same internal sequence generator. 13. Which Process reads data from Datafiles? Server Process - There is no background process which reads data from datafile or database buffer. Oracle creates server processes to handle requests from connected user processes. A server process communicates with the user process and interacts with Oracle to carry out requests from the associated user process. For example, if a user queries some data not already in the database buffers of the SGA, then the associated server process reads the proper data blocks from the datafiles into the SGA. Oracle can be configured to vary the number of user processes for each server process. In a dedicated server configuration, a server process handles requests for a single user process. A shared server configuration lets many user processes share a small number of server processes, minimizing the number of server processes and maximizing the use of available system resources. 14. Which Process writes data in Datafiles? Database Writer background process DBWn (20 possible) writes dirty buffers from the buffer cache to the data files. In other words, this process writes modified blocks permanently to disk.
Prepared by: Nasser

9|Page

15. Can you make a Datafile auto extendible? If yes how? YES. A Datafile can be auto extendible. Here's how to enable auto extend on a Datafile:
SQL>alter database datafile '/u01/app/oracle/product/10.2.0/oradata/DBSID/EXAMPLE01.DBF' autoextend on ;

Note: For tablespaces defined with multiple data files (and partitioned table files), only the "last" data file needs the autoextend option.
SQL>spool runts.sql SQL>select 'alter database datafile '|| file_name|| ' '|| ' autoextend on;' from dba_data_files; SQL>@runts

16. What is a Shared Pool? The shared pool portion of the SGA contains the library cache, the dictionary cache, buffers for parallel execution messages, and control structures. The total size of the shared pool is determined by the initialization parameter SHARED_POOL_SIZE. The default value of this parameter is 8MB on 32-bit platforms and 64MB on 64-bit platforms. Increasing the value of this parameter increases the amount of memory reserved for the shared pool. 17. What is kept in the Database Buffer Cache? The database buffer cache is the portion of the SGA that holds copies of data blocks read from datafiles. All user processes concurrently connected to the instance share access to the database buffer cache. 18. How many maximum Redo Logfiles one can have in a Database? Maximum number of logfiles is limited by value of MAXLOGFILES parameter in the CREATE DATABASE statement. Control file can be resized to allow more entries; ultimately an operating system limit. Maximum number of logfiles per group - Unlimited Consider the parameters that can limit the number of redo log files before setting up or altering the configuration of an instance redo log. The following parameters limit the number of redo log files that you can add to a database: MAXLOGFILES & MAXLOGMEMBERS. The MAXLOGFILES parameter used in the CREATE DATABASE statement determines the maximum number of groups of redo log files for each database. Group values can range from 1 to MAXLOGFILES. When the compatibility level is set earlier than 10.2.0, the only way to override this upper limit is to re-create the database or its control file. Therefore, it is important to consider this limit before creating a database. When compatibility is set to 10.2.0 or later, you can exceed the MAXLOGFILES limit, and the control files expand as needed. If MAXLOGFILES is not specified for the CREATE DATABASE statement, then the database uses an operating system specific default value. The MAXLOGMEMBERS parameter used in the CREATE DATABASE statement determines the maximum number of members for each group. As with MAXLOGFILES, the only way to override this upper limit is to re-create the database or control file. Therefore, it is important to consider this limit before creating a database. If no MAXLOGMEMBERS parameter is specified for the CREATE DATABASE statement, then the database uses an operating system default value. 19. What is difference between PFile and SPFile?

Prepared by: Nasser

10 | P a g e

A PFILE is a static, text file located in $ORACLE_HOME/dbs - UNIX An SPFILE (Server Parameter File) is a persistent server-side binary file that can only be modified with the "ALTER SYSTEM SET" command. 20. What is PGA_AGGREGATE_TARGET parameter? PGA_AGGREGATE_TARGET: specifies the target aggregate PGA memory available to all server processes attached to the instance. 21. Large Pool is used for what? The large pool is an optional memory area and provides large memory allocations for: Session memory for the shared server and the Oracle XA interface (used where transactions interact with more than one database) I/O server processes, buffer area Oracle backup and restore operations (RMAN) User Global Area (UGA) for shared servers 22. What is PCT Increase setting? PCTINCREASE refers to the percentage by which each next extent (beginning with the third extend) will grow. The size of each subsequent extent is equal to the size of the previous extent plus this percentage increase. Preventing tablespace fragmentation Try to set PCTINCREASE to 0 or 100. Bizarre values for PCTINCREASE will contribute to fragmentation. For example if you set PCTINCREASE to 1 you will see that your extents are going to have weird and wacky sizes: 100K, 100K, 101K, 102K, etc. Such extents of bizarre size are rarely re-used in their entirety. PCTINCREASE of 0 or 100 gives you nice round extent sizes that can easily be reused. Eg.100K, 100K, 200K, 400K, etc. Locally Managed tablespaces (available from Oracle 8i onwards) with uniform extent sizes virtually eliminates any tablespace fragmentation. Note that the number of extents per segment does not cause any performance issue anymore, unless they run into thousands and thousands where additional I/O may be required to fetch the additional blocks where extent maps of the segment are stored. 23. What is PCTFREE and PCTUSED Setting? PCTFREE is a block storage parameter used to specify how much space should be left in a database block for future updates. For example, for PCTFREE=10, Oracle will keep on adding new rows to a block until it is 90% full. This leaves 10% for future updates (row expansion). When using Oracle Advanced Compression, Oracle will trigger block compression when the PCTFREE is reached. This eliminates holes created by row deletions and maximizes contiguous free space in blocks. See the PCTFREE setting for a table:
SQL> SELECT pct_free FROM user_tables WHERE table_name = 'EMP'; PCT_FREE ---------10

PCTUSED is a block storage parameter used to specify when Oracle should consider a database block to be empty enough to be added to the freelist. Oracle will only insert new rows in blocks that isenqueued on the freelist.

Prepared by: Nasser

11 | P a g e

For example, if PCTUSED=40, Oracle will not add new rows to the block unless sufficient rows are deleted from the block so that it falls below 40% empty. 24. What is Row Migration and Row Chaining? Row Migration refers to rows that were moved to another blocks due to an update making them too large to fit into their original blocks. Oracle will leave a forwarding pointer in the original block so indexes will still be able to "find" the row. Note that Oracle does not discriminate between chained and migrated rows, even though they have different causes. A chained row is a row that is too large to fit into a single database data block. For example, if you use a 4KB blocksize for your database, and you need to insert a row of 8KB into it, Oracle will use 3 blocks and store the row in pieces. Some conditions that will cause row chaining are: Tables whose row size exceeds the blocksize Tables with long and long raw columns are prone to having chained rows Tables with more than 255 columns will have chained rows as Oracle break wide tables up into pieces. Detecting row chaining: This query will show how many chained (and migrated) rows each table has:
SQL>SELECT owner, table_name, chain_cnt FROM dba_tables WHERE chain_cnt> 0;

To see which rows are chained:


SQL>ANALYZE TABLE tablename LIST CHAINED ROWS;

This will put the rows into the INVALID_ROWS table which is created by the utlvalid.sql script (located in $ORACLE_HOME/rdbms/admin). 25. What is ORA-01555 - Snapshot Too Old error and how do you avoid it? The ORA-01555 is caused by Oracle read consistency mechanism. If you have a long running SQL that starts at 11:30 AM, Oracle ensures that all rows are as they appeared at 11:30 AM, even if the query runs until noon! Oracles does this by reading the "before image" of changed rows from the online undo segments. If you have lots of updates, long running SQL and too small UNDO, the ORA-01555 error will appear. ORA-01555 error relates to insufficient undo storage or a too small value for the undo_retention parameter: ORA-01555: snapshot too old: rollback segment number string with name "string" too small Cause: Rollback records needed by a reader for consistent read are overwritten by other writers. Action: If in Automatic Undo Management mode, increase the setting of UNDO_RETENTION. Otherwise, use larger rollback segments. You can get an ORA-01555 error with a too-small undo_retention, even with a large undo tables. However, you can set a super-high value for undo_retention and still get an ORA-01555 error. The ORA-01555 snapshot too old error can be addressed by several remedies: Re-schedule long-running queries when the system has less DML load Increasing the size of your rollback segment (undo) size The ORA-01555 snapshot too old also relates to your setting for automatic undo retention Don't fetch between commits

26. What is a Locally Managed Tablespace?

Prepared by: Nasser

12 | P a g e

Locally Managed Tablespace is a tablespace that record extent allocation in the tablespace header. Each tablespace manages its own free and used space within a bitmap structure stored in one of the tablespace's data files. Advantages of Locally Managed Tablespaces: Eliminates the need for recursive SQL operations against the data dictionary (UET$ and FET$ tables) Reduce contention on data dictionary tables (single ST enqueue) Locally managed tablespaces eliminate the need to periodically coalesce free space (automatically tracks adjacent free space) Changes to the extent bitmaps do not generate rollback information 27. Can you audit SELECT statements? YES. But beware; you will need a storage mechanism to hold your SQL SELECT audits, a high data volume that can exceed the size of your whole database, every day. SQL SELECT auditing can be accomplished in several ways: Oracle audit table command: audit SELECT table by FRED by access; Oracle Fined-grained Auditing

In a busy database, the volume of the SELECT audit trail could easily exceed the size of the database every data. Plus, all data in the audit trail must also be audited to see who has selected data from the audit trail. 28. What does DBMS_FGA package do? The DBMS_FGA package provides fine-grained security functions. DBMS_FGA is a PL/SQL package used to define Fine Grain Auditing on objects. DBMS_FGA Package Subprograms: ADD_POLICY Procedure - Creates an audit policy using the supplied predicate as the audit condition DISABLE_POLICY Procedure - Disables an audit policy DROP_POLICY Procedure - Drops an audit policy ENABLE_POLICY Procedure - Enables an audit policy 29. What is Cost Based Optimization? The Oracle Cost Based Optimizer (CBO) is a SQL Query optimizer that uses data statistics to identify the query plan with lowest cost before execution. The cost is based on the number of rows in a table, index efficiency, etc. All applications should be converted to use the Cost Based Optimizer as the Rule Based Optimizer is not be supported in Oracle 10g and above releases. 30. How often you should collect statistics for a table? Analyse if it's necessary! - Refresh STALE statistics before the batch processes run but only for tables involved in batch run, - Don't do it if you don't have to. - Oracle databse has default, scheduled job "gather_stats_job" that analyses stats on a daily basis during the maintenance window time. 31. How do you collect statistics for a table, schema and Database? Using DBMS_STATS package to gather Oracle dictionary statistics.

Prepared by: Nasser

13 | P a g e

32. Can you make collection of Statistics for tables automatically? YES. Oracle databse has default, scheduled job "gather_stats_job" that analyses stats on a daily basis during the maintenance window time. There are two scheduled activities related to the collection of Oracle "statistics": AWR statistics: Oracle has an automatic method to collect AWR "snapshots" of data that is used to create elapsed-time performance reports. Optimizer statistics: Oracle has an automatic job to collect statistics to help the optimizer make intelligent decisions about the best access method to fetch the desired rows.

This job can be disabled with this command: exec dbms_scheduler.disable(SYS.GATHER_STATS_JOB); Oracle collects optimizer statistics for SQL via the default of autostats_target = auto. 33. On which columns you should create Indexes? In general, you should create an index on a column in any of the following situations: The column is queried frequently A referential integrity constraint exists on the column A UNIQUE key integrity constraint exists on the column The following list gives guidelines in choosing columns to index: You should create indexes on columns that are used frequently in WHERE clauses Are used frequently to join tables Are used frequently in ORDER BY clauses On columns that have few of the same values or unique values in the table 34. What type of indexes are available in Oracle? There are many index types within Oracle: B*Tree Indexes - common indexes in Oracle. They are similar construct to a binary tree; they provide fast access by key, to an individual row or range of rows, normally requiring very few reads to find the correct row. The B*Tree index has several subtypes: Index Organised Tables - A table stored in a B*Tree structure B*Tree Cluster Indexes - They are used to index the cluster keys Reverse Key Indexes - The bytes in the key are reversed. This is used to stop sequential keys being on the same block like 999001, 999002, 999003 would be reversed to 100999, 200999, 300999 thus these would be located on different blocks. Descending Indexes - They allow data to be sorted from big to small (descending) instead of small to big (ascending). Bitmap Indexes - With a bitmap index, a single index entry uses a bitmap to point to many rows simultaneously, they are used with low data that is mostly read-only. Schould be avoided in OLTP systems. Function Based Indexes - These are B*Tree or bitmap indexes that store the computed result of a function on a row(s) (for example sorted results)- not the column data itself. Application Domain Indexes - These are indexes you build and store yourself, either in Oracle or outside of Oracle interMedia Text Indexes - This is a specialized index built into Oracle to allow for keyword searching of large bodies of text. 35. What is B-Tree Index?

Prepared by: Nasser

14 | P a g e

A B-Tree index is a data structure in the form of a tree, but it is a tree of database blocks, not rows. Note: "B" is not for binary; it's balanced. 36. A table is having few rows, should you create indexes on this table Small tables do not require indexes; if a query is taking too long, then the table might have grown from small to large. You can create an index on any column; however, if the column is not used in any of these situations, creating an index on the column does not increase performance and the index takes up resources unnecessarily. 37. A Column is having many repeated values which type of index you should create on this column, if you have to? For example, assume there is a motor vehicle database with numerous low-cardinality columns such as car_color, car_make, car_model, and car_year. Each column contains less than 100 distinct values by themselves, and a btree index would be fairly useless in a database of 20 million vehicles. 38. When should you rebuilt indexes? In 90% cases - NEVER. When the data in index is sparse (lots of holes in index, due to deletes or updates) and your query is usually range based. Also index blevel is one of the key indicators of performance of sql queries doing Index range scans. 39. Can you built indexes online? YES. You can create and rebuild indexes online. This enables you to update base tables at the same time you are building or rebuilding indexes on that table. You can perform DML operations while the index build is taking place, but DDL operations are not allowed. Parallel execution is not supported when creating or rebuilding an index online. The following statements illustrate online index build operations: CREATE INDEX emp_name ON emp (mgr, emp1, emp2, emp3) ONLINE; 40. Can you see Execution Plan of a statement? YES. In many ways, for example from GUI based tools like TOAD, Oracle SQL Developer. Configuring AUTOTRACE, a SQL*Plus facility AUTOTRACE is a facility within SQL*Plus to show us the explain plan of the queries we've executed, and the resources they used. Once the PLAN_TABLE has been installed in the database, You can control the report by setting the AUTOTRACE system variable. SET AUTOTRACE OFF - No AUTOTRACE report is generated. This is the default. SET AUTOTRACE ON EXPLAIN - The AUTOTRACE report shows only the optimizer execution path. SET AUTOTRACE ON STATISTICS - The AUTOTRACE report shows only the SQL statement execution statistics. SET AUTOTRACE ON - The AUTOTRACE report includes both the optimizer execution path and the SQL statement execution statistics. SET AUTOTRACE TRACEONLY - Like SET AUTOTRACE ON, but suppresses the printing of the user's query output, if any. 41. A table has been created with below settings. What will be size of 4th extent? storage (initial 200k next 200k
Prepared by: Nasser

15 | P a g e

minextents 2 maxextents 100 pctincrease 40) What will be size of 4th extent? "NEXT" Specify in bytes the size of the next extent to be allocated to the object. Percent Increase allows your segment to grow at an increasing rate. The first two extents will be of a size determined by the Initial and Next parameter (200k) The third extent will be 1 + PCTINCREASE/100 times the second extent (1,4*200=280k). AND The fourth extent will be 1 + PCTINCREASE/100 times the third extent (1,4*280=392k!!!), and so on... 42. What is DB Buffer Cache Advisor? The Buffer Cache Advisor provides advice on how to size the Database Buffer Cache to obtain optimal cache hit ratios. Member of Performance Advisors --> Memory Advisor pack. 43. What is STATSPACK tool? STATSPACK is a performance diagnosis tool provided by Oracle starting from Oracle 8i and above. STATSPACK is a diagnosis tool for instance-wide performance problems; it also supports application tuning activities by providing data which identifies high-load SQL statements. Although AWR and ADDM (introduced in Oracle 10g) provide better statistics than STATSPACK, users that are not licensed to use the Enterprise Manager Diagnostic Pack should continue to use statspack. More information about STATSPACK, can be found in file $ORACLE_HOME/rdbms/admin/spdoc.txt. 44. Can you change SHARED_POOL_SIZE online? YES. That's possible. SQL>alter system set shared_pool_size=500M scope=both; System altered. It's a lot quicker to bounce the instance when changing this. 45. Can you Redefine a table Online? Yes you can. In any database system, it is occasionally necessary to modify the logical or physical structure of a table to: Improve the performance of queries or DML Accommodate application changes Manage storage Oracle Database provides a mechanism to make table structure modifications without significantly affecting the availability of the table. The mechanism is called online table redefinition. When a table is redefined online, it is accessible to both queries and DML during much of the redefinition process. The table is locked in the exclusive mode only during a very small window that is independent of the size of the table and complexity of the redefinition and that is completely transparent to users. Online table redefinition requires an amount of free space that is approximately equivalent to the space used by the table being redefined. More space may be required if new columns are added.

Prepared by: Nasser

16 | P a g e

You can perform online table redefinition with the Enterprise Manager Reorganize Objects wizard or with the DBMS_REDEFINITION package. 46. Can you assign Priority to users? YES. This is achievable with Oracle Resource Manager. DBMS_RESOURCE_MANAGER is the packcage to administer the Database Resource Manager. The DBMS_RESOURCE_MANAGER package maintains plans, consumer groups, and plan directives. It also provides semantics so that you may group together changes to the plan schema. 47. You want users to change their passwords every 2 months. How do you enforce this? Oracle password security is implemented via Oracle "profiles" which are assigned to users. PASSWORD_LIFE_TIME - limits the number of days the same password can be used for authentication First, start by creating security "profile" in Oracle database and then alter the user to belong to the profile group. 1) Creating a profile:
create profile all_users limit PASSWORD_LIFE_TIME 60 PASSWORD_GRACE_TIME 10 PASSWORD_REUSE_TIME UNLIMITED PASSWORD_REUSE_MAX 0 FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME UNLIMITED;

2) Create user and assign user to the all_users profile


SQL>create user chuck identified by norris profile all_users;

3) To "alter profile" parameter, say; change to three months:


SQL>alter profile all_users set PASSWORD_LIFE_TIME = 90;

48. How do you delete duplicate rows in a table? There is a few ways to achieve that: Using subquery to delete duplicate rows:
DELETE FROM table_name WHERE rowid NOT IN (SELECT max(rowid) FROM table_name GROUP BY id);

More ways: Use RANK to find and remove duplicate table rows Use self-join to remove duplicate rows Use analytics to detect and remove duplicate rows Delete duplicate table rows that contain NULL values 49. What is Automatic Management of Segment Space setting? Oracle9i New Feature Series: Automatic Segment Space Management Automatic Segment Space Management (ASSM) introduced in Oracle9i is an easier way of managing space in a segment using bitmaps. It eliminates the DBA from setting the parameters pctused, freelists, and freelist groups. ASSM can be specified only with the locally managed tablespaces (LMT). Oracle uses bitmaps to manage the free space. Bitmaps allow Oracle to manage free space more automatically.

Prepared by: Nasser

17 | P a g e

Here is an example:
CREATE TABLESPACE example DATAFILE '/oradata/ORA_SID/example01.dbf' SIZE 50M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 2M SEGMENT SPACE MANAGEMENT AUTO;

The storage parameters PCTUSED, FREELISTS and FREELIST GROUPS specified while creating a table are ignored by Oracle on a LMT ASSM tablespace. Oracle does not produce an error. One huge benefit of having ASSM is to reduce the Buffer Busy Waits you see on segments. Beware: Using ASSM can hinder database DML performance, and most Oracle experts will use manual freelists and freelist groups. 50. What is the difference between DELETE and TRUNCATE statements? The DELETE command is used to remove rows from a table. A WHERE clause can be used to only remove some rows. If no WHERE condition is specified, all rows will be removed. After performing a DELETE operation you need to COMMIT or ROLLBACK the transaction to make the change permanent or to undo it. DELETE will cause all DELETE triggers on the table to fire. TRUNCATE removes all rows from a table. A WHERE clause is not permited. The operation cannot be rolled back and no triggers will be fired. As such, TRUCATE is faster and doesn't use as much undo space as a DELETE. 51. What is COMPRESS and CONSISTENT setting in EXPORT utility? COMPRESS Simply: COMPRESS=n - Allocated space in database for imported table will be exactly as the space required to hold the data. COMPRESS=y - The INITIAL extent of the table would be as large as the sum of all the extents allocated to the table in the original database. In other words: The default, COMPRESS=y, causes Export to flag table data for consolidation into one initial extent upon import. If extent sizes are large (for example, because of the PCTINCREASE parameter), the allocated space will be larger than the space required to hold the data. If you specify COMPRESS=n, Export uses the current storage parameters, including the values of initial extent size and next extent size. If you are using locally managed tablespaces you should always export with COMPRESS=n CONSISTENT Default: n. Specifies whether or not Export uses the SET TRANSACTION READ ONLY statement to ensure that the data seen by Export is consistent to a single point in time and does not change during the execution of the exp command. You should specify CONSISTENT=y when you anticipate that other applications will be updating the target data after an export has started. If you use CONSISTENT=n, each table is usually exported in a single transaction. However, if a table contains nested tables, the outer table and each inner table are exported as separate transactions. If a table is partitioned, each partition is exported as a separate transaction. Therefore, if nested tables and partitioned tables are being updated by other applications, the data that is exported could be inconsistent. To minimize this possibility, export those tables at a time when updates are not being done.

Prepared by: Nasser

18 | P a g e

52. What is the difference between Direct Path and Conventional Path loading? A conventional path load executes SQL INSERT statements to populate tables in an Oracle database. A direct path load eliminates much of the Oracle database overhead by formatting Oracle data blocks and writing the data blocks directly to the database files. 53. Can you disable and enable Primary key? You can use the ALTER TABLE statement to enable, disable, modify, or drop a constraint. When the database is using a UNIQUE or PRIMARY KEY index to enforce a constraint, and constraints associated with that index are dropped or disabled, the index is dropped, unless you specify otherwise. While enabled foreign keys reference a PRIMARY or UNIQUE key, you cannot disable or drop the PRIMARY or UNIQUE key constraint or the index. Disabling Enabled Constraints The following statements disable integrity constraints. The second statement specifies that the associated indexes are to be kept.
ALTER TABLE dept DISABLE CONSTRAINT dname_ukey; ALTER TABLE dept DISABLE PRIMARY KEY KEEP INDEX, DISABLE UNIQUE (dname, loc) KEEP INDEX;

The following statements enable novalidate disabled integrity constraints:


ALTER TABLE dept ENABLE NOVALIDATE CONSTRAINT dname_ukey; ALTER TABLE dept ENABLE NOVALIDATE PRIMARY KEY, ENABLE NOVALIDATE UNIQUE (dname, loc);

The following statements enable or validate disabled integrity constraints:


ALTER TABLE dept MODIFY CONSTRAINT dname_key VALIDATE; ALTER TABLE dept MODIFY PRIMARY KEY ENABLE NOVALIDATE;

The following statements enable disabled integrity constraints:


ALTER TABLE dept ENABLE CONSTRAINT dname_ukey; ALTER TABLE dept ENABLE PRIMARY KEY, ENABLE UNIQUE (dname, loc);

To disable or drop a UNIQUE key or PRIMARY KEY constraint and all dependent FOREIGN KEY constraints in a single step, use the CASCADE option of the DISABLE or DROP clauses. For example, the following statement disables a PRIMARY KEY constraint and any FOREIGN KEY constraints that depend on it:
ALTER TABLE dept DISABLE PRIMARY KEY CASCADE;

54. What is an Index Organized Table? An index-organized table (IOT) is a type of table that stores data in a B*Tree index structure. Normal relational tables, called heap-organized tables, store rows in any order (unsorted). In contrast to this, index-organized tables store rows in a B-tree index structure that is logically sorted in primary key order. Unlike normal primary key indexes, which store only the columns included in it definition, IOT indexes store all the columns of the table (an exception to this rule - is being called the overflow area). Properties and restrictions: An IOT must contain a primary key Rows are accessed via a logical rowid and not a physical rowid like in heap-organized tables An IOT cannot be in a cluster An IOT cannot contain a column of LONG data type

Prepared by: Nasser

19 | P a g e

You cannot modify an IOT index property using ALTER INDEX (error ORA-25176), you must use an ALTER TABLE instead.

Advantages of an IOT As an IOT has the structure of an index and stores all the columns of the row, accesses via primary key conditions are faster as they don't need to access the table to get additional column values. As an IOT has the structure of an index and is thus sorted in the order of the primary key, accesses of a range of primary key values are also faster. As the index and the table are in the same segment, less storage space is needed. In addition, as rows are stored in the primary key order, you can further reduce space with key compression. As all indexes on an IOT uses logical rowids, they will not become unusable if the table is reorganized. Row overflow area If some columns of the table are infrequently accessed, it is possible to offload them into another segment named the overflow area. An overflow segment will decrease the size of the main (or top) segment and will increase the performance of statements that do not need access the columns in the overflow area. Notes: The overflow area can contains only columns that are not part of the primary key. If a row cannot fit in a block, you must define an overflow area. Consequently, the primary key values of an IOT must fit in a single block. The columns of the table that are recorded in the overflow segment are defined using the PCTHRESHOLD and/or INCLUDING options of the OVERFLOW clause (examples on source website). 55. What is a Global Index and Local Index? Local Index - each partition of a local index is associated with exactly one partition of the table. Global Index - global index is associated with multiple partitions of the table. Oracle offers two types of global partitioned index: - Global Range Partitioned Indexes - Global Hash Partitioned Indexes Global Nonpartitioned Indexes - behave just like a nonpartitioned index. 56. What is the difference between Range Partitioning and Hash Partitioning? Range Partitioning maps data to partitions based on a range of column values (e.g. a date column) Hash Partitioning maps data to partitions based on a hashing algorithm, evenly distributing data between the partitions. This is typically used where ranges aren't appropriate, i.e. customer number, product ID 57. What is difference between Multithreaded/Shared Server and Dedicated Server? Oracle Database creates server processes to handle the requests of user processes connected to an instance. A server process can be either of the following: - A dedicated server process, which services only one user process - A shared server process, which can service multiple user processes Your database is always enabled to allow dedicated server processes, but you must specifically configure and enable shared server by setting one or more initialization parameters.
Prepared by: Nasser

20 | P a g e

58. Can you import objects from Oracle ver. 7.3 to 9i? Different versions of the import utility are upwards compatible. This means that one can take an export file created from an old export version, and import it using a later version of the import utility. Oracle also ships some previous catexpX.sql scripts that can be executed as user SYS enabling older imp/exp versions to work (for backwards compatibility). For example, one can run $ORACLE_HOME/rdbms/admin/catexp7.sql on an Oracle 8 database to allow the Oracle 7.3 exp/imp utilities to run against an Oracle 8 database. 59. How do you move tables from one tablespace to another tablespace? There are several methods to do this; 1) export the table, drop the table, create the table definition in the new tablespace, and then import the data (imp ignore=y). 2) Create a new table in the new tablespace with the CREATE TABLE statement AS SELECT all from source table command:
CREATE TABLE temp_name TABLESPACE new_tablespace AS SELECT * FROM source_table;

Then drop the original table and rename the temporary table as the original:
DROP TABLE real_table; RENAME temp_name TO real_table;

Note: don't forget to rebuild any indexes. 60. How to display how much space is used and free in a tablespace? Example query to check free and used space per tablespace:
SELECT /* + RULE */ df.tablespace_name "Tablespace", df.bytes / (1024 * 1024) "Size (MB)", SUM(fs.bytes) / (1024 * 1024) "Free (MB)", NVL( ROUND(SUM(fs.bytes) * 100 / df.bytes),1) "% Free", ROUND((df.bytes - SUM(fs.bytes)) * 100 / df.bytes) "% Used" FROM dba_free_spacefs, ( SELECT tablespace_name,SUM(bytes) bytes FROM dba_data_files GROUP BY tablespace_name ) df WHERE fs.tablespace_name (+) = df.tablespace_name GROUP BY df.tablespace_name,df.bytes UNION ALL SELECT /* + RULE */ df.tablespace_nametspace, fs.bytes / (1024 * 1024), SUM(df.bytes_free) / (1024 * 1024), NVL(ROUND((SUM(fs.bytes) - df.bytes_used) * 100 / fs.bytes), 1), ROUND((SUM(fs.bytes) - df.bytes_free) * 100 / fs.bytes) FROM dba_temp_filesfs, ( SELECT tablespace_name,bytes_free,

Prepared by: Nasser

21 | P a g e

bytes_used FROM v$temp_space_header GROUP BY tablespace_name,bytes_free, bytes_used ) df WHERE fs.tablespace_name (+) = df.tablespace_name GROUP BY df.tablespace_name,fs.bytes, df.bytes_free,df.bytes_used; Sample output: Tablespace Size (MB) Free (MB) % Free % Used ------------------------------ ---------- ---------- ---------- ---------UNDOTBS1 65 17.8125 27 73 EXAMPLE 100 22.625 23 77 USERS 5 1.0625 21 79 TEMP 20 2 10 90 SYSAUX 625.125 54.5 9 91 SYSTEM 700 9.0625 1 99

Prepared by: Nasser

22 | P a g e

Part 3:
What is a Database? a) A database is an organized collection of data for one or more purposes, usually in digital form. b) A database is a collection of information that is organized so that it can easily be accessed, managed, and updated. c) A database is the collection of files that contains the data. In Oracle its ending with .dbf extension and these are binary files Types of Databases: There are several common types of databases; each type of database has its own data model (how the data is structured). They include: Flat Model, Hierarchical Model, Network Model, andRelational Model. 1. The Flat Model Database: In a flat model database, there is a two dimensional (flat structure) array of data. For instance, there is one column of information and within this column it is assumed that each data item will be related to the other. For instance, a flat model database includes only zip codes. Within the database, there will only be one column and each new row within that one column will be a new zip code. 2. The Hierarchical Model Database: The hierarchical model database resembles a tree like structure, such as how Microsoft Windows organizes folders and files. In a hierarchical model database, each upward link is nested in order to keep data organized in a particular order on a same level list. For instance, a hierarchal database of sales, may list each days sales as a separate file. Within this nested file are all of the sales (same types of data) for the day. 3. The Network Model Database: In a network model, the defining feature is that a record is stored with a link to other records in effect networked. These networks (or sometimes referred to as pointers) can be a variety of different types of information such as node numbers or even a disk address. 4. The Relational Model Database: The relational model is the most popular type of database and an extremely powerful tool, not only to store information, but to access it as well. Relational databases are organized as tables. The beauty of a table is that the information can be accessed or added without reorganizing the tables. A table can have many records and each record can have many fields. What is an Instance? a) The term instance is typically used to describe a complete database environment, including the RDBMS software, table structure, stored procedures and other functionality. It is most commonly used when administrators describe multiple instances of the same database. b) An instance is just collection of background processes and memory structures, used to tap in to the database.
Prepared by: Nasser

23 | P a g e

Also Known As: environment Example: An organization with an employees database might have three different instances: Production (used to contain live data), Pre-production (used to test new functionality prior to release into production) and Development (used by database developers to create new functionality). Data Management Data Management is a broad field of study, but essentially is the process of managing data as a resource that is valuable to an organization or business. One of the largest organizations that deal with data management, DAMA (Data Management Association), states that data management is the process of developing data architectures, practices and procedures dealing with data and then executing these aspects on a regular basis. There are many topics within data management, some of the more popular topics include data modeling, data warehousing, data movement, database administration and data mining. Data Modeling Data modeling is first creating a structure for the data that you collect and use and then organizing this data in a way that is easily accessible and efficient to store and pull the data for reports and analysis. In order to create a structure for data, it must be named appropriately and show a relationship with other data. It also must fit appropriately in a class. For instance, if you have a database of media, you might have a hierarchal structure of objects that include photos, videos, and audio files. Within each category, you can classify objects accordingly. Data Warehousing Data warehousing is storing data effectively so that it can be accessed and used efficiently. Different organizations collect different types of data, but many organizations use their data the same way, in order to create reports and analyze their data to make quality business decisions. Data warehousing is usually an organizational wide repository of data, however for very large corporations in can encompass just one office or one department. Data Movement Data movement is the ability to move data from one place to another. For instance, data needs to be moved from where it is collected to a database and then to an end user, but this process takes quite a bit of logistic insight. Not only do all hardware, applications and data collected need to be compatible with one another, they must also be able to be classified, stored and accessed with ease within an organization. Moving data can be very expensive and can require lots of resources to make sure that data is moved efficiently, that data is secure in transit and that once it reaches the end user it can be used effectively either to be printed out as a report, saved on a computer or sent as an email attachment. Data Mining Another important topic regarding data management is data mining. Data mining is a process in which large amounts of data are sifted through to show trends, relationships, and patterns. Data mining is a
Prepared by: Nasser

24 | P a g e

crucial component to data management because it exposes interesting information about the data being collected. It is important to note that data is primarily collected so it can be used to find these patterns, relationships and trends that can help a business grow or create profit. Database Administration Database administration is extremely important in managing data. Every organization or enterprise needs database administrators that are responsible for the database environment. Database administrators are usually given the authority to do the following tasks that include recoverability, integrity, security, availability, performance and development & testing support.

Some Basics command of ORACLE 10g on Windows Operating System: SQL> show parameter db_name SQL> show parameter instance_name SQL> show parameterdb_block_size (it will show the default block size which is 8KB)

Abbreviations:
SGA: PGA: pfile: spfile: CKPT: DBW: LGWR: ARC0: PMON: SMON: System Global Area Program Global Area Parameter File Server Parameter File Check Point Database Writer Log Writer Archiver Process Monitor System Monitor

What is a Table? A Table is the primary unit of physical storage in a database. Usually a database contains more than one table. What is an Entity? An entity is a business object represents a group or category of data. Data Types: Alphanumeric (Text, Memo) Numeric (Number, Currency, etc.) Date/Time Boolean (Yes/No)

Prepared by: Nasser

25 | P a g e

Oracle Memory Structure


Figure 1:

CKPT (Check Point): --------------------------------DBW (Database Writer): ---------------------------LGWR (Log Writer): ----------------------------------ARC0 (Archiver): ------------------------------------PMON (Process Monitor): ------------------------SMON (System Monitor): ---------------------------

How to check Oracle services on Windows and UNIX systems: a) On Windows system click on Task Manager and then processes tab, you will Oracle process b) On UNIX system use the below command: # ps -ef | grep oracle

Prepared by: Nasser

26 | P a g e

Physical Structure of Database


Usually a database has the below files: a) b) c) d) e) f) g) h) Data Files (*.dbf) ------------------Redo Logs (*.log) ------------------Undo (*.dbf) ------------------------Spfile or init file --------------------Alert Log (*.log) --------------------Trace Files (*.trc) -------------------Control Files (*.ctl) ------------------Backup Files ----------------------------

Figure 2:

Prepared by: Nasser

27 | P a g e

Figure 3: Log files location and size query

Logical Storage Structure


Figure 4:

Prepared by: Nasser

28 | P a g e

a) b) c) d) e)

SYSTEM TABLESPACE: SYSAUX TABLESPACE: UNDO TABLESPACE: TEMP TABLESPACE: DATA TABLESPCAE:

Startup, Shutdown and Oracle Initialization File


Figure 5:

Prepared by: Nasser

29 | P a g e

Figure 6:

Prepared by: Nasser

30 | P a g e

Figure 7: startup database:

Data Dictionary Views


Figure 7: Data Dictionary Views

Prepared by: Nasser

31 | P a g e

Figure 8: Data Dictionary View:

Prepared by: Nasser

32 | P a g e

Managing Tables, Views, Constraints and Sequences


What is Table? What is View? What is Constraint? What is Sequence?

Data Moving Utilities:


Figure 9:

Four Types of Exports: 1. 2. 3. 4. Full Database Export Schema Export Table Export Tablespace Export

Prepared by: Nasser

33 | P a g e

Transportable Tablespaces

Prepared by: Nasser

34 | P a g e

Prepared by: Nasser

35 | P a g e

PL/SQL (Procedural Language / Structural Query Language

Prepared by: Nasser

36 | P a g e

Prepared by: Nasser

37 | P a g e

1. What is database? A database is a logically coherent collection of data with some inherent meaning, representing some aspect of real world and which is designed, built and populated with data for a specific purpose. 2. What is DBMS? It is a collection of programs that enables user to create and maintain a database. In other words it is general-purpose software that provides the users with the processes of defining, constructing and manipulating the database for various applications. 3. What is a Database system? The database and DBMS software together is called as Database system. 4. Advantages of DBMS?

Redundancy is controlled. Unauthorized access is restricted. Providing multiple user interfaces. Enforcing integrity constraints. Providing backup and recovery.

5. Disadvantage in File Processing System?


Data redundancy & inconsistency. Difficult in accessing data. Data isolation. Data integrity. Concurrent access is not possible. Security Problems.

6. Describe the three levels of data abstraction? There are three levels of abstraction:

Physical level: The lowest level of abstraction describes how data are stored. Logical level: The next higher level of abstraction, describes what data are stored in database and what relationship among those data. View level: The highest level of abstraction describes only part of entire database.

Prepared by: Nasser

38 | P a g e

7. Define the integrity rules There are two Integrity rules.


Entity Integrity: States that Primary key cannot have NULL value Referential Integrity: States that Foreign Key can be either a NULL value or should be Primary Key value of other relation.

8. What is extension and intension? Extension It is the number of tuples present in a table at any instance. This is time dependent. Intension It is a constant value that gives the name, structure of table and the constraints laid on it. 9. What is System R? What are its two major subsystems? System R was designed and developed over a period of 1974-79 at IBM San Jose Research Center. It is a prototype and its purpose was to demonstrate that it is possible to build a Relational System that can be used in a real life environment to solve real life problems, with performance at least comparable to that of existing system. Its two subsystems are

Research Storage System Relational Data System.

10. How is the data structure of System R different from the relational structure? Unlike Relational systems in System R

Domains are not supported Enforcement of candidate key uniqueness is optional Enforcement of entity integrity is optional Referential integrity is not enforced

11. What is Data Independence? Data independence means that the application is independent of the storage structure and access strategy of data. In other words, The ability to modify the schema definition i n one level should not affect the schema definition in the next higher level. Two types of Data Independence:

Physical Data Independence: Modification in physical level should not affect the logical level. Logical Data Independence: Modification in logical level should affect the view level.

Prepared by: Nasser

39 | P a g e

NOTE: Logical Data Independence is more difficult to achieve 12. What is a view? How it is related to data independence? A view may be thought of as a virtual table, that is, a table that does not really exist in its own right but is instead derived from one or more underlying base table. In other words, there is no stored file that direct represents the view instead a definition of view is stored in data dictionary. Growth and restructuring of base tables is not reflected in views. Thus the view can insulate users from the effects of restructuring and growth in the database. Hence accounts for logical data independence. 13. What is Data Model? A collection of conceptual tools for describing data, data relationships data semantics and constraints. 14. What is E-R model? This data model is based on real world that consists of basic objects called entities and of relationship among these objects. Entities are described in a database by a set of attributes. 15. What is Object Oriented model? This model is based on collection of objects. An object contains values stored in instance variables with in the object. An object also contains bodies of code that operate on the object. These bodies of code are called methods. Objects that contain same types of values and the same methods are grouped together into classes. 16. What is an Entity? It is a thing in the real world with an independent existence. 17. What is an Entity type? It is a collection (set) of entities that have same attributes. 18. What is an Entity set? It is a collection of all entities of particular entity type in the database. 19. What is an Extension of entity type? The collections of entities of a particular entity type are grouped together into an entity set.
Prepared by: Nasser

40 | P a g e

20. What is Weak Entity set? An entity set may not have sufficient attributes to form a primary key, and its primary key compromises of its partial key and primary key of its parent entity, then it is said to be Weak Entity set. 21. What is an attribute? It is a particular property, which describes the entity. 22. What is a Relation Schema and a Relation? A relation Schema denoted by R(A1, A2, , An) is made up of the relation name R and the list of attributes Ai that it contains. A relation is defined as a set of tuples. Let r be the relation which contains set tuples (t1, t2, t3, ,tn). Each tuple is an ordered list of n -values t=(v1,v2, , vn). 23. What is degree of a Relation? It is the number of attribute of its relation schema. 24. What is Relationship? It is an association among two or more entities. 25. What is Relationship set? The collection (or set) of similar relationships. 26. What is Relationship type? Relationship type defines a set of associations or a relationship set among a given set of entity types. 27. What is degree of Relationship type? It is the number of entity type participating. 25. What is DDL (Data Definition Language)? A data base schema is specifies by a set of definitions expressed by a special language called DDL. 26. What is VDL (View Definition Language)?
Prepared by: Nasser

41 | P a g e

It specifies user views and their mappings to the conceptual schema. 27. What is SDL (Storage Definition Language)? This language is to specify the internal schema. This language may specify the mapping between two schemas. 28. What is Data Storage - Definition Language? The storage structures and access methods used by database system are specified by a set of definition in a special type of DDL called data storage-definition language. 29. What is DML (Data Manipulation Language)? This language that enable user to access or manipulate data as organised by appropriate data model.

Procedural DML or Low level: DML requires a user to specify what data are needed and how to get those data. Non-Procedural DML or High level: DML requires a user to specify what data are needed without specifying how to get those data.

31. What is DML Compiler? It translates DML statements in a query language into low-level instruction that the query evaluation engine can understand. 32. What is Query evaluation engine? It executes low-level instruction generated by compiler. 33. What is DDL Interpreter? It interprets DDL statements and record them in tables containing metadata. 34. What is Record-at-a-time? The Low level or Procedural DML can specify and retrieve each record from a set of records. This retrieve of a record is said to be Record-at-a-time. 35. What is Set-at-a-time or Set-oriented?

Prepared by: Nasser

42 | P a g e

The High level or Non-procedural DML can specify and retrieve many records in a single DML statement. This retrieve of a record is said to be Set-at-a-time or Set-oriented. 36. What is Relational Algebra? It is procedural query language. It consists of a set of operations that take one or two relations as input and produce a new relation. 37. What is Relational Calculus? It is an applied predicate calculus specifically tailored for relational databases proposed by E.F. Codd. E.g. of languages based on it are DSL ALPHA, QUEL. 38. How does Tuple-oriented relational calculus differ from domain-oriented relational calculus? The tuple-oriented calculus uses a tuple variables i.e., variable whose only permitted values are tuples of that relation. E.g. QUEL The domain-oriented calculus has domain variables i.e., variables that range over the underlying domains instead of over relation. E.g. ILL, DEDUCE. 39. What is normalization? It is a process of analysing the given relation schemas based on their Functional Dependencies (FDs) and primary key to achieve the properties

Minimizing redundancy Minimizing insertion, deletion and update anomalies.

40. What is Functional Dependency? A Functional dependency is denoted by X Y between two sets of attributes X and Y that are subsets of R specifies a constraint on the possible tuple that can form a relation state r of R. The constraint is for any two tuples t1 and t2 in r if t1[X] = t2[X] then they have t1[Y] = t2[Y]. This means the value of X component of a tuple uniquely determines the value of component Y. 41. When is a functional dependency F said to be minimal?

Every dependency in F has a single attribute for its right hand side. We cannot replace any dependency X A in F with a dependency Y A where Y is a proper subset of X and still have a set of dependency that is equivalent to F. We cannot remove any dependency from F and still have set of dependency that is equivalent to F.
43 | P a g e

Prepared by: Nasser

42. What is Multivalued dependency? Multivalued dependency denoted by X Y specified on relation schema R, where X and Y are both subsets of R, specifies the following constraint on any relation r of R: if two tuples t1 and t2 exist in r such that t1[X] = t2[X] then t3 and t4 should also exist in r with the following properties

t3[x] = t4[X] = t1[X] = t2[X] t3[Y] = t1[Y] and t4[Y] = t2[Y] t3[Z] = t2[Z] and t4[Z] = t1[Z]

where [Z = (R-(X U Y)) ] 43. What is Lossless join property? It guarantees that the spurious tuple generation does not occur with respect to relation schemas after decomposition. 44. What is 1 NF (Normal Form)? The domain of attribute must include only atomic (simple, indivisible) values. 45. What is Fully Functional dependency? It is based on concept of full functional dependency. A functional dependency X Y is full functional dependency if removal of any attribute A from X means that the dependency does not hold any more. 46. What is 2NF? A relation schema R is in 2NF if it is in 1NF and every non-prime attribute A in R is fully functionally dependent on primary key. 47. What is 3NF? A relation schema R is in 3NF if it is in 2NF and for every FD X A either of the following is true

X is a Super-key of R. A is a prime attribute of R.

In other words, if every non prime attribute is non-transitively dependent on primary key. 48. What is BCNF (Boyce-Codd Normal Form)?
Prepared by: Nasser

44 | P a g e

A relation schema R is in BCNF if it is in 3NF and satisfies an additional constraint that for every FD X A, X must be a candidate key. 49. What is 4NF? A relation schema R is said to be in 4NF if for every Multivalued dependency X Y that holds over R, one of following is true

X is subset or equal to (or) XY = R. X is a super key.

50. What is 5NF? A Relation schema R is said to be 5NF if for every join dependency {R1, R2, ,Rn} that holds R, one the following is true

Ri = R for some i. The join dependency is implied by the set of FD, over R in which the left side is key of R.

51. What is Domain-Key Normal Form? A relation is said to be in DKNF if all constraints and dependencies that should hold on the the constraint can be enforced by simply enforcing the domain constraint and key constraint on the relation. 52. What are partial, alternate,, artificial, compound and natural key? Partial Key: It is a set of attributes that can uniquely identify weak entities and that are related to same owner entity. It is sometime called as Discriminator. Alternate Key: All Candidate Keys excluding the Primary Key are known as Alternate Keys. Artificial Key: If no obvious key, either stand alone or compound is available, then the last resort is to simply create a key, by assigning a unique number to each record or occurrence. Then this is known as developing an artificial key. Compound Key: If no single data element uniquely identifies occurrences within a construct, then combining multiple elements to create a unique identifier for the construct is known as creating a compound key. Natural Key:
Prepared by: Nasser

45 | P a g e

When one of the data elements stored within a construct is utilized as the primary key, then it is called the natural key. 53. What is indexing and what are the different kinds of indexing? Indexing is a technique for determining how quickly specific data can be found. Types:

Binary search style indexing B-Tree indexing Inverted list indexing Memory resident table Table indexing

54. What is system catalog or catalog relation? How is better known as? A RDBMS maintains a description of all the data that it contains, information about every relation and index that it contains. This information is stored in a collection of relations maintained by the system called metadata. It is also called data dictionary. 55. What is meant by query optimization? The phase that identifies an efficient execution plan for evaluating a query that has the least estimated cost is referred to as query optimization. 56. What is join dependency and inclusion dependency? Join Dependency: A Join dependency is generalization of Multivalued dependency.A JD {R1, R2, ,Rn} is said to hold over a relation R if R1, R2, R3, , Rn is a lossless-join decomposition of R . There is no set of sound and complete inference rules for JD. Inclusion Dependency: An Inclusion Dependency is a statement of the form that some columns of a relation are contained in other columns. A foreign key constraint is an example of inclusion dependency. 57. What is durability in DBMS? Once the DBMS informs the user that a transaction has successfully completed, its effects should persist even if the system crashes before all its changes are reflected on disk. This property is called durability. 58. What do you mean by atomicity and aggregation? Atomicity:

Prepared by: Nasser

46 | P a g e

Either all actions are carried out or none are. Users should not have to worry about the effect of incomplete transactions. DBMS ensures this by undoing the actions of incomplete transactions. Aggregation: A concept which is used to model a relationship between a collection of entities and relationships. It is used when we need to express a relationship among relationships. 59. What is a Phantom Deadlock? In distributed deadlock detection, the delay in propagating local information might cause the deadlock detection algorithms to identify deadlocks that do not really exist. Such situations are called phantom deadlocks and they lead to unnecessary aborts. 60. What is a checkpoint and When does it occur? A Checkpoint is like a snapshot of the DBMS state. By taking checkpoints, the DBMS can reduce the amount of work to be done during restart in the event of subsequent crashes. 61. What are the different phases of transaction? Different phases are

Analysis phase Redo Phase Undo phase

62. What do you mean by flat file database? It is a database in which there are no programs or user access languages. It has no cross-file capabilities but is user-friendly and provides user-interface management. 63. What is transparent DBMS? It is one, which keeps its Physical Structure hidden from user. 64. Brief theory of Network, Hierarchical schemas and their properties Network schema uses a graph data structure to organize records example for such a database management system is CTCG while a hierarchical schema uses a tree data structure example for such a system is IMS. 65. What is a query? A query with respect to DBMS relates to user commands that are used to interact with a data base. The query language can be classified into data definition language and data manipulation
Prepared by: Nasser

47 | P a g e

language. 66. What do you mean by Correlated subquery? Subqueries, or nested queries, are used to bring back a set of rows to be used by the parent query. Depending on how the subquery is written, it can be executed once for the parent query or it can be executed once for each row returned by the parent query. If the subquery is executed for each row of the parent, this is called a correlated subquery. A correlated subquery can be easily identified if it contains any references to the parent subquery columns in its WHERE clause. Columns from the subquery cannot be referenced anywhere else in the parent query. The following example demonstrates a non-correlated subquery. E.g. Select * From CUST Where 10/03/1990? IN (Select ODATE From ORDER Where CUST.CNUM = ORDER.CNUM) 67. What are the primitive operations common to all record management systems? Addition, deletion and modification. 68. Name the buffer in which all the commands that are typed in are stored Edit Buffer 69. What are the unary operations in Relational Algebra? PROJECTION and SELECTION. 70. Are the resulting relations of PRODUCT and JOIN operation the same? No. PRODUCT: Concatenation of every row in one relation with every row in another. JOIN: Concatenation of rows from one relation and related rows from another. 71. What is RDBMS KERNEL? Two important pieces of RDBMS architecture are the kernel, which is the software, and the data dictionary, which consists of the system-level data structures used by the kernel to manage the database You might think of an RDBMS as an operating system (or set of subsystems), designed specifically for controlling data access; its primary functions are storing, retrieving, and securing data. An RDBMS maintains its own list of authorized users and their associated privileges; manages memory caches and paging; controls locking for concurrent resource usage; dispatches and schedules user requests; and manages space usage within its table-space structures.
Prepared by: Nasser

48 | P a g e

72. Name the sub-systems of a RDBMS I/O, Security, Language Processing, Process Control, Storage Management, Logging and Recovery, Distribution Control, Transaction Control, Memory Management, Lock Management 73. Which part of the RDBMS takes care of the data dictionary? How Data dictionary is a set of tables and database objects that is stored in a special area of the database and maintained exclusively by the kernel. 74. What is the job of the information stored in data-dictionary? The information in the data dictionary validates the existence of the objects, provides access to them, and maps the actual physical storage location. 75. Not only RDBMS takes care of locating data it also determines an optimal access path to store or retrieve the data 76. How do you communicate with an RDBMS? You communicate with an RDBMS using Structured Query Language (SQL) 77. Define SQL and state the differences between SQL and other conventional programming Languages SQL is a nonprocedural language that is designed specifically for data access operations on normalized relational database structures. The primary difference between SQL and other conventional programming languages is that SQL statements specify what data operations should be performed rather than how to perform them. 78. Name the three major set of files on disk that compose a database in Oracle There are three major sets of files on disk that compose a database. All the files are binary. These are

Database files Control files Redo logs

The most important of these are the database files where the actual data resides. The control files and the redo logs support the functioning of the architecture itself. All three sets of files must be present, open, and available to Oracle for any data on the database to be useable. Without these files, you cannot access the database, and the database
Prepared by: Nasser

49 | P a g e

administrator might have to recover some or all of the database using a backup, if there is one. 79. What is an Oracle Instance? The Oracle system processes, also known as Oracle background processes, provide functions for the user processesfunctions that would otherwise be done by the user processes themselves Oracle database-wide system memory is known as the SGA, the system global area or shared global area. The data and control structures in the SGA are shareable, and all the Oracle background processes and user processes can use them. The combination of the SGA and the Oracle background processes is known as an Oracle instance 80. What are the four Oracle system processes that must always be up and running for the database to be useable The four Oracle system processes that must always be up and running for the database to be useable include DBWR (Database Writer), LGWR (Log Writer), SMON (System Monitor), and PMON (Process Monitor).

81. What are database files, control files and log files. How many of these files should a database have at least? Why?

Database Files The database files hold the actual data and are typically the largest in size. Depending on their sizes, the tables (and other objects) for all the user accounts can go in one database filebut thats not an ideal situation because it does not make the database structure very flexible for controlling access to storage for different users, putting the database on different disk drives, or backing up and restoring just part of the database. You must have at least one database file but usually, more than one files are used. In terms of accessing and using the data in the tables and other objects, the number (or location) of the files is immaterial. The database files are fixed in size and never grow bigger than the size at which they were created Control Files The control files and redo logs support the rest of the architecture. Any database must have at least one control file, although you typically have more than one to guard against loss. The control file records the name of the database, the date and time it was created, the location of the database and redo logs, and the synchronization information to ensure that all three sets of files are always in step. Every time you add a new database or redo log file to the database, the information is recorded in the control files. Redo Logs Any database must have at least two redo logs. These are the journals for the database;
50 | P a g e

Prepared by: Nasser

the redo logs record all changes to the user objects or system objects. If any type of failure occurs, the changes recorded in the redo logs can be used to bring the database to a consistent state without losing any committed transactions. In the case of non-data loss failure, Oracle can apply the information in the redo logs automatically without intervention from the DBA. The redo log files are fixed in size and never grow dynamically from the size at which they were created.

82. What is ROWID? The ROWID is a unique database-wide physical address for every row on every table. Once assigned (when the row is first inserted into the database), it never changes until the row is deleted or the table is dropped. The ROWID consists of the following three components, the combination of which uniquely identifies the physical storage location of the row.

Oracle database file number, which contains the block with the rows Oracle block address, which contains the row The row within the block (because each block can hold many rows)

The ROWID is used internally in indexes as a quick means of retrieving rows with a particular key value. Application developers also use it in SQL statements as a quick way to access a row once they know the ROWID 83. What is Oracle Block? Can two Oracle Blocks have the same address? Oracle formats the database files into a number of Oracle blocks when they are first createdmaking it easier for the RDBMS software to manage the files and easier to read data into the memory areas. The block size should be a multiple of the operating system block size. Regardless of the block size, the entire block is not available for holding data; Oracle takes up some space to manage the contents of the block. This block header has a minimum size, but it can grow. These Oracle blocks are the smallest unit of storage. Increasing the Oracle block size can improve performance, but it should be done only when the database is first created. Each Oracle block is numbered sequentially for each database file starting at 1. Two blocks can have the same block address if they are in different database files. 84. What is database Trigger? A database trigger is a PL/SQL block that can defined to automatically execute for insert, update, and delete statements against a table. The trigger can e defined to execute once for the entire statement or once for every row that is inserted, updated, or deleted. For any one table, there are twelve events for which you can define database triggers. A database trigger can call
Prepared by: Nasser

51 | P a g e

database procedures that are also written in PL/SQL. 85. Name two utilities that Oracle provides, which are use for backup and recovery. Along with the RDBMS software, Oracle provides two utilities that you can use to back up and restore the database. These utilities are Export and Import. The Export utility dumps the definitions and data for the specified part of the database to an operating system binary file. The Import utility reads the file produced by an export, recreates the definitions of objects, and inserts the data If Export and Import are used as a means of backing up and recovering the database, all the changes made to the database cannot be recovered since the export was performed. The best you can do is recover the database to the time when the export was last performed. 86. What are stored-procedures? And what are the advantages of using them. Stored procedures are database objects that perform a user defined operation. A stored procedure can have a set of compound SQL statements. A stored procedure executes the SQL commands and returns the result to the client. Stored procedures are used to reduce network traffic. 87. 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;
Prepared by: Nasser

52 | P a g e

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. 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. 88. 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. 89. Tables derived from the ERD a) Are totally unnormalised b) Are always in 1NF c) Can be further denormalised
Prepared by: Nasser

53 | P a g e

d) May have multi-valued attributes (b) Are always in 1NF 90. Spurious tuples may occur due to i. Bad normalization ii. Theta joins iii. Updating tables from join a) i& ii b) ii & iii c) i& iii d) ii & iii (a) i& iii because theta joins are joins made on keys that are not primary keys. 91. A B C is a set of attributes. The functional dependency is as follows AB -> B AC -> C C -> B a) is in 1NF b) is in 2NF c) is in 3NF d) 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. 92. In mapping of ERD to DFD a) entities in ERD should correspond to an existing entity/store in DFD b) entity in DFD is converted to attributes of an entity in ERD c) relations in ERD has 1 to 1 correspondence to processes in DFD d) relationships in ERD has 1 to 1 correspondence to flows in DFD (a) entities in ERD should correspond to an existing entity/store in DFD 93. A dominant entity is the entity a) on the N side in a 1 : N relationship b) on the 1 side in a 1 : N relationship c) on either side in a 1 : 1 relationship d) nothing to do with 1 : 1 or 1 : N relationship (b) on the 1 side in a 1 : N relationship 94. Select NORTH, CUSTOMER From CUST_DTLS Where REGION = N Order By CUSTOMER Union Select EAST, CUSTOMER From CUST_DTLS Where REGION = E Order By
Prepared by: Nasser

54 | P a g e

CUSTOMER The above is a) Not an error b) Error - the string in single quotes NORTH and SOUTH c) Error - the string should be in double quotes d) Error - ORDER BY clause (d) Error - the ORDER BY clause. Since ORDER BY clause cannot be used in UNIONS 95. 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. 96. 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. 97. 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. 98. 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. 99. 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. 100. 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. 101. What are cursors give different types of cursors.

Prepared by: Nasser

55 | P a g e

PL/SQL uses cursors for all database information accesses statements. The language supports the use two types of cursors

Implicit Explicit

102. 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.

103. 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.

Prepared by: Nasser

56 | P a g e

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. 104. 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 1. Set X+ = X 2. Set Old X+ = X+ 3. For each FD Y Z in F and if Y belongs to X+ then add Z to X+ 4. Repeat steps 2 and 3 until Old X+ = X+ Algo.II Determining minimal K for relation schema R, given set of FDs F 1. Set K to R that is make K a set of all attributes in R 2. For each attribute A in K a. Compute (K A)+ with respect to F b. If (K A)+ = R then set K = (K A)+ 105. 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 106. 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 .

Prepared by: Nasser

57 | P a g e

Simulatneous Update: The updates that are applied to database at the same time when it becomes effective in real world .

107. 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

Prepared by: Nasser

58 | P a g e

You might also like