Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

ORACLE SQL

MOST ASKED SQL and PLSQL INTERVIEW QUESTIONS AND ANSWERS

1. Difference between Primary Key and Unique key


SLNO PRIMARY KEY UNIQUE KEY
1 Primary Key is keyword which determines Unique key is a keyword which supports
column to be unique on a table uniqueness of a column when a table doesn’t
have primary key
2 Primary key will not accept Null Values Unique key will accept null values
3 The primary key tends to generate a The unique key tends to generate a non-
clustered index by default. clustered index.
4 Primary key support entity Integrity Unique will support Uniqueness of data
5 A Table can have only one Primary key A Table can have multiple Unique keys
6 Data Present in Primary key can not be Data Present in Unique key can be change and
change or modify. modify
7 It is used to recognize specific records in It anticipates storing duplicate entries in a
the table. column except for a NULL value.

2. Differences between Primary Key and Foreign key


SLNO PRIMARY KEY FOREIGN KEY
1 Primary key is used to Uniquely Identify a Foreign key is used to establish the connection
record Uniquely between two tables
2 Primary key can not accept Null and Foreign key can accept null and duplicate value.
duplicate Values
3 A table can allow only one primary key A table can have more than one primary key
4 Primary key is Combination of Not null Foreign key is not a combination
and Unique key
5 Table having primary key can referred as Table having foreign key is referred as Child
Parent table table
6 We cannot modify or change value We can modify or change value present in
present in primary key foreign key

3. Differences between Simple view and Complex Views


SLNO SIMPLE VIEW COMPLEX VIEW
1 Simple vie contains single base table and Complex view contains more than one base
is formed by single table table and is created by more than one table
2 We Cannot use Group function like We can use group functions in complex view
max(), Count() etc..,
3 Simple view does not contain group of Complex view contains group of data
data
4 DML Operations could be performed DML operations could not always perform
through simple vies through complex view
5 Simple view does not contain group by, It can contain group by, distinct,
distinct, pseudocolumn like rownum, pseudocolumn like rownum, columns
columns defined by expressions. defined by expressions.
ORACLE SQL

4. Differences between Procedures and Functions


SLNO PROCEDURES FUNCTIONS
1 Procedures are used to perform Functions are used to perform calculation
certain tasks
2 Procedures are optionally returns Functions must return Values
value using out and inout
parameters
3 DML operations can perform in DML Operations cannot perform in Functions
procedures (Note: There is a restriction DML operation functions
can not call by select statement
By specifying Autonomous transaction, we can
perform)
4 A procedure cannot call from A Function can be called from procedure
Function
5 A Procedure cannot call by SELECT A Function can call from SELECT Statement
Statement
6 Procedure can use explicit A Function will not use explicit transaction handling
transaction handling

5. Difference between Bitmpa and b-tree Index.


SLNO BITMAP INDEX B-TREE INDEX
1 The bitmap Index Includes BITMAP In B-tree Index Not required to Explicitly specify any
Keyword keyword
2 Bit map is used for Low Cardinality B-tree Index is used for high cardinality columns
columns (With lots of duplicate
values)

6. Differences between cursors and ref cursor.


SLNO CURSORS REF CURSOR
1 A Cursor is static Ref Cursor is Dynamic
2 A Cursor is defined at compile time Ref Cursor is defined at runtime
3 A cursor must be used in simple for A Ref cursor can not be used in cursor for loop
loop
4 We can use cursors globally we can not use ref cursor out side the procedures
and functions
5 A cursor retrives data more A ref cursor is not much efficient as regular cursor
efficiently
ORACLE SQL

7. Differences between Union and Union all


SLNO UNION UNION ALL
1 Union operator holds only Unique Whereas in union all it returns both matched and
records unmatched values

8. Difference between Delete and truncate


SLNO DELETE TRUNCATE
1 Delete is DML Statement Truncate is DDL Statement
2 We can use where clause as a filter we can not use where clause in Truncate
condition in Delete
3 Data can be roll back after Delete Data can not be roll back after drop
4 After delete transaction need to After Truncate data commit automatically
commit Explicitly
5 Trigger will fire on delete Trigger will not fire on Truncate
6 Delete is slow Truncate is fast
7 In Delete entire row will be locked In Truncate entire table is locked during transaction
during transaction

9. Differences between Drop and Truncate.


SLNO DROP TRUNCATE
1 It is used to eliminate the whole It is used to eliminate the tuples from the table.
database from the table.
2 Integrity constraints get removed in Integrity constraint doesn’t get removed in the
the DROP command. Truncate command
3 The structure of the table does not The structure of the table exists.
exist.
4 Here the table is free from memory. Here, the table is not free from memory.
5 It is slow as compared to the It is fast as compared to the DROP command.
TRUNCATE command.

10.Differences between view and materialized views.


SLNO VIEWS MATERIALIZED VIEWS
1 Views are virtual. They only display Materialized views are physical copy of the table
2 Views does not store any data on Materialized view will store data
the disk
3 Views will get updated each and Materialized views need to update manually
every time we call view
4 Views are used for security purpose Materialized views are used to improve performance
5 It does not have any updation cost It does have an updation cost associates with it.
associates with it
ORACLE SQL

11.Differences between Cluster and Not Cluster Index

S.No Clustered Non-clustered

1 A clustered index is used to define the A non-clustered index collects the data at one place
order or to sort the table or arrange the and records at another place.
data by alphabetical order just like a
dictionary.

2 It is faster than a non-clustered index. It is slower than the clustered index.

3 It demands less memory to execute the It demands more memory to execute the
operation. operations.

4 It permits you to save data sheets in the It never saves data sheets in the leaf nodes of the
leaf nodes of the index. index.

5 A single table can consist of a sole It can consist of multiple non-clustered indexes.
cluster index.

6 It has the natural ability to store data on It does not have the natural strength to store data on
the disk. the disk.

12.Differences between where Clause and Having Clause.


SLNO WHERE CLAUSE HAVING CLAUSE
1 Where Clause filters records Having clause filter groups
2 Where clause executes row by row Having Clause will execute group by group
3. Where clause will execute before the Having Clause will execute after the execution
execution of Group by Clause of group by clause
4 We cannot use multirow functions in We can use multirow functions in Having
where clause clause
5 Where clause can be used without group Having clause is used with group by clause
by clause
6 Where clause can be used with Having clause can only use with Select
Select,Update,Insert and delete statement
7 Where clause can be used with single row Having clause is used with multi row functions
functions like UPPER, LOWER etc like MAX(), MIN() etc..,

You might also like