SQL Interview Questions and Answers

1)What are the Back ground processes in Oracle and what are they?
Data Base Writer (DBWR): Data Base Writer Writes Modified blocks from Database buffer cache to Data Files. This is required since the data is not written whenever a transaction is committed.
Log Writer (LGWR): Log writer writes the redo log entries to disk. Redo Log data is generated in redo log buffer of SGA. As transaction commits and logs buffer fills, LGWR writes log entries into an online redo log file.
System Monitor (SMON): The System Monitor performs instance recovery at instance startup. This is useful for recovery from system failure
Process Monitor (PMON): The Process Monitor performs process recovery when user Process fails. PMON Clears and Frees resources that process was using.
Check Point (CKPT): At Specified times, all modified database buffers in SGA are written to data files by DBWR at Checkpoints and Updating all data files and control files of database to indicate the most recent checkpoint
Achieves (ARCH): The Archiver copies online redo log files to archival storal when they are busy.
Recover or (RECO): The Recovered is used to resolve the distributed transaction in network
Dispatcher (Dnnn): The Dispatcher is useful in Multi Threaded Architecture
Lckn: We can have up to 10 lock processes for interred instance locking in parallel
SQL.

2)What is a Transaction in Oracle?
A transaction is a Logical unit of work that compromises one or more SQL Statements executed by a single User. According to ANSI, a transaction begins with first executable statement and ends when it is explicitly committed or rolled back.

3)What are Procedure, functions and Packages?
Procedures and functions consist of set of PL/SQL statements that are grouped together as a unit to solve a specific problem or perform set of related tasks. Procedures do not return values while Functions return one Value
Packages: Packages provide a method of encapsulating and storing related procedures, functions, variables and other Package Contents

4)How many types of SQL Statements are there in Oracle
There are basically 6 types of SQL statements. They are
Data Definition Language (DDL): The DDL statements define and maintain objects and drop objects.
Data Manipulation Language (DML): The DML statements manipulate database data.
Transaction Control Statements: Manage change by DML
Session Control: Used to control the properties of current session enabling and disabling roles and changing. E.g. Alter Statements, Set Role
System Control Statements: Change Properties of Oracle Instance. E.g.: Alter System
Embedded SQL: Incorporate DDL, DML and T.C.S in Programming Language.
E.g. Using the SQL Statements in languages such as ‘C’, Open, Fetch, execute and
close

5)Key Words Used in Oracle
The Key words that are used in Oracle are
Committing: A transaction is said to be committed when the transaction makes permanent changes resulting from the SQL statements.
Rollback: A transaction that retracts any of the changes resulting from SQL statements in Transaction.
Save Point: For long transactions that contain many SQL statements, intermediate markers or save points are declared. Save points can be used to divide a transaction into smaller points.
Rolling Forward: Process of applying redo log during recovery is called rolling forward.
Cursor: A cursor is a handle (name or a pointer) for the memory associated with a specific stamen. A cursor is basically an area allocated by Oracle for executing the SQL Statement. Oracle uses an implicit cursor statement for Single row query and Uses Explicit cursor for a multi row query.
System Global Area (SGA): The SGA is a shared memory region allocated by the Oracle that contains Data and control information for one Oracle Instance. It consists of Database Buffer Cache and Redo log Buffer.
Program Global Area (PGA): The PGA is a memory buffer that contains data and control information for server process.
Database Buffer Cache: Database Buffer of SGA stores the most recently used blocks of database data. The set of database buffers in an instance is called Database Buffer Cache.
Redo log Buffer: Redo log Buffer of SGA stores all the redo log entries.
Redo Log Files: Redo log files are set of files that protect altered database data in memory that has not been written to Data Files. They are basically used for backup when a database crashes.
Process: A Process is a ‘thread of control’ or mechanism in Operating System that executes series of steps

READ  PL/SQL interview questions and answers

.
6)What are Database Triggers and Stored Procedures?
Database Triggers: Database Triggers are Procedures that are automatically executed as a result of insert in, update to, or delete from table.
Database triggers have the values old and new to denote the old value in the table before it is deleted and the new indicated the new value that will be used. Database Triggers are useful for implementing complex business rules, which cannot be enforced using the integrity rules. We can have the trigger as before trigger or After Trigger and at Statement or Row level.
E.g.: operations insert, update, and delete 3
Before, after 3*2 A total of 6 combinations
At statement level (once for the trigger) or row level (for every execution) 6 * 2 A
total of 12.
Thus a total of 12 combinations are there and the restriction of usage of 12 triggers has been lifted from Oracle 7.3 Onwards.
Stored Procedures: Stored Procedures are Procedures that are stored in Compiled form in the database. The advantage of using the stored procedures is that many users can use the same procedure in compiled and ready to use format.

7)How many Integrity Rules are there and what are they?
There are Three Integrity Rules. They are as follows:
Entity Integrity Rule: The Entity Integrity Rule enforces that the Primary key cannot be Null
Foreign Key Integrity Rule: The FKIR denotes that the relationship between the foreign
key and the primary key has to be enforced. When there is data in Child Tables the
Master tables cannot be deleted.
Business Integrity Rules: The Third Integrity rule is about the complex business processes
which cannot be implemented by the above 2 rules.

8)What are the Various Master and Detail Relation ships?
The various Master and Detail Relationship are
Non Isolated: The Master cannot be deleted when a child is existing
Isolated: The Master can be deleted when the child is existing
Cascading: The child gets deleted when the Master is deleted.

9)What are the Various Block Coordination Properties?
The various Block Coordination Properties are Immediate Default Setting. The Detail records are shown when the Master Record are shown. Deferred with Auto Query Oracle Forms defer fetching the detail records until the operator navigates to the detail block. Deferred with No Auto Query The operator must navigate to the detail block and explicitly execute a query

10)What are the Different Optimisation Techniques?
The Various Optimization techniques are
Execute Plan: we can see the plan of the query and change it accordingly based on the indexes
Optimizer hint: set_item_property(‘DeptBlock’,OPTIMIZER_HINT,’FIRST_ROWS’);
Select /*+ First_Rows */ Deptno,Dname,Loc,Rowid from dept
where (Deptno > 25)
Optimize_Sql: By setting the Optimize_Sql = No, Oracle Forms assigns a single cursor for
all SQL statements. This slow downs the processing because for evertime the SQL must
be parsed whenever they are executed.
F45run module = my_firstform userid = scott/tiger optimize_sql = No
Optimize_Tp: By setting the Optimize_Tp= No, Oracle Forms assigns seperate cursor only
for each query SELECT statement. All other SQL statements reuse the cursor.
f45run module = my_firstform userid = scott/tiger optimize_Tp = No

11)How do u implement the If statement in the Select Statement?
We can implement the if statement in the select statement by using the Decode
statement.
e.g select DECODE (EMP_CAT,’1′,’First’,’2′,’Second’Null);
Here the Null is the else statement where null is done .

12)How many types of Exceptions are there?
There are 2 types of exceptions. They are
System Exceptions: e.g. When no_data_found, When too_many_rows
User Defined Exceptions: e.g. My_exception exception,When My_exception then

13)What are the inline and the precompiler directives?
The inline and precompiler directives detect the values directly

14)How do you use the same lov for 2 columns?
We can use the same lov for 2 columns by passing the return values in global values and using the global values in the code

READ  PL/SQL interview questions and answers

15)How many minimum groups are required for a matrix report?
The minimum number of groups in matrix report are 4

16)What is the difference between static and dynamic LOV?
The static LOV contains the predetermined values while the dynamic LOV contains
values that come at runtime.

17)What are snap shots and views?
Snapshots are mirror or replicas of tables. Views are built using the columns from one or more tables. The Single Table View can be updated but the view with multi table cannot be updated

18)What are the OOPS concepts in Oracle?
Oracle does implement the OOPS concepts. The best example is the Property Classes. We can categories the properties by setting the visual attributes and then attach the property classes for the objects. OOPS supports the concepts of objects and classes and we can consider the property classes as classes and the items as objects

19)What is the difference between candidate key, unique key and primary key?
Candidate keys are the columns in the table that could be the primary keys and the primary key is the key that has been selected to identify the rows. Unique key is also useful for identifying the distinct rows in the table.

20)What is concurrency?
Concurrency is allowing simultaneous access of same data by different users. Locks useful for accessing the database are
a) Exclusive: The exclusive lock is useful for locking the row when an insert, update or delete is being done. This lock should not be applied when we do only select from the row.
b) Share lock: We can do the table as Share Lock as many share locks can be put on the same resource.

21)Privileges and Grants?
Privileges are the right to execute a particular type of SQL statements.
E.g.: Right to Connect, Right to create, Right to resource
Grants are given to the objects so that the object might be accessed accordingly. The grant has to be given by the owner of the object.

22)What are the Pct Free and Pct Used?
Pct Free is used to denote the percentage of the free space that is to be left when creating a table. Similarly Pct Used is used to denote the percentage of the used space that is to be used when creating a table
Pctfree 20, Pctused 40

23)Table Space, Data Files, Parameter File, Control Files?
Table Space: The table space is useful for storing the data in the database. When a database is created two table spaces are created.
a) System Table space: This data file stores all the tables related to the system and DBA tables
b) User Table space: This data file stores all the user related tables
We should have separate table spaces for storing the tables and indexes so that the
access is fast.
Data Files: Every Oracle Data Base has one or more physical data files. They store the
data for the database. Every data file is associated with only one database. Once the
data file is created the size cannot change. To increase the size of the database to
store more data we have to add data file.
Parameter Files: Parameter file is needed to start an instance. A parameter file contains
the list of instance configuration parameters
E.g. Db_block_buffers = 500
Byname = ORA7
db_domain = u.s.acme lang
Control Files: Control files record the physical structure of the data files and redo log files
They contain the Db name, name and location of dbs, data files, redo log files and time
stamp.

24)Physical Storage of the Data?
The finest level of granularity of the database are the data blocks.
Data Block: One Data Block correspond to specific number of physical database space
Extent: Extent is the number of specific number of contigious data blocks.
Segments: Set of Extents allocated for Extents. There are three types of Segments
a) Data Segment: Non Clustered Table has data segment data of every table is stored in cluster data segment
b) Index Segment: Each Index has index segment that stores data
c) Roll Back Segment: Temporarily store ‘undo’ information

READ  PL/SQL interview questions and answers

26)What is Row Chaining?
The data of a row in a table may not be able to fit the same data block. Data for row is stored in a chain of data blocks.
28)What is a 2 Phase Commit
Two Phase commit is used in distributed data base systems. This is useful to maintain the integrity of the database so that all the users see the same values. It contains DML statements or Remote Procedural calls that reference a remote object. There are basically 2 phases in a 2 phase commit.
a) Prepare Phase: Global coordinator asks participants to prepare
b) Commit Phase: Commit all participants to coordinator to Prepared, Read only or
abort Reply

27)What is the difference between deleting and truncating of tables?
Deleting a table will not remove the rows from the table but entry is there in the database dictionary and it can be retrieved But truncating a table deletes it completely and it cannot be retrieved.

28)what are the datatypes supported By oracle (INTERNAL)?
Varchar2, Number, Char, MLSLABEL.

29)What are attributes of cursor?
%FOUND , %NOTFOUND , %ISOPEN,%ROWCOUNT
Can you use select in FROM clause of SQL select?
what is the significance of SQLCODE & SQLERRM in pl/SQL exception handler?
For internal exceptions, SQLCODE returns the number of the Oracle error. The number that SQLCODE returns is negative unless the Oracle error is no data found, in which case SQLCODE returns +100.
SQLERRM: returns the corresponding error message. The message begins with the Oracle error code. For user-defined exceptions, SQLCODE returns +1 and SQLERRM returns the message
User-Defined Exception: If no exception has been raised, SQLCODE returns zero and SQLERRM returns the message

30)What are mutating tables?
When a table is in state of transition it is said to be mutating.
E.g. If a row has been deleted then the table is said to be mutating and no operations can be done on the table except select.

31)What are Codd Rules?
Codd Rules describe the ideal nature of a RDBMS. No RDBMS satisfies all the 12 codd rules and Oracle Satisfies 11 of the 12 rules and is the only Rdbms to satisfy the maximum number of rules.

32)What is Normalization?
Normalization is the process of organising the tables to remove the redundancy. There are mainly 5 Normalisation rules.
a) 1 Normal Form : A table is said to be in 1st Normal Form when the attributes are atomic
b) 2 Normal Form: A table is said to be in 2nd Normal Form when all the candidate keys are dependant on the primary key
c) 3rd Normal Form : A table is said to be third Normal form when it is not dependant transitively

33)What is the Difference between a post query and a pre query?
A post query will fire for every row that is fetched but the pre query will fire only once.

34)Deleting the Duplicate rows in the table?
We can delete the duplicate rows in the table by using the Rowid

35)Can U disable database trigger? How?
Yes. With respect to table
ALTER TABLE TABLE [DISABLE all_trigger ]

36)What is pseudo columns ? Name them?
A pseudo column behaves like a table column, but is not actually stored in the table. You
can select from pseudocolumns, but you cannot insert, update, or delete their values. This
section describes these pseudocolumns:
*CURRVAL, *NEXTVAL, *LEVEL, *ROWID, * ROWNUM

37)How many columns can table have?
The number of columns in a table can range from 1 to 254.

38)Is space acquired in blocks or extents?
In extents .

39)what is clustered index?
In an indexed cluster, rows are stored together based on their cluster key values .
Can not applied for HASH.

Leave a Reply

Your email address will not be published. Required fields are marked *