Skip to main content

Difference between clustered and Non-Clustered Indexes in Oracle Sql PLSQL Interview Question and Answer.

 "It is an important question which is asked in an interview as indexing topic."

INTRODUCTION:

In the SQL server, primary key constraint automatically builds the clustered index on the column. There will be only one clustered index per table. It is used to sort the data of the table alphabetically as like dictionary structure. Single table can contain multiple non-clustered indexes. It collects the data and record at one place simultaneously.

CLUSTERED INDEX:

It is the kind of the special type of index which reorders the ways that the records of data of the table are physically stored to match with an index. Whenever the primary key constraint is created on the table, database engine by auto creates the clustered index. View or data are sorted based on the key and values. It stores the data permanently on the disk.

It is created only when both the below conditions are satisfied:
Moved data or file in the secondary memory should be sequential and properly sorted fashion.
Key value should be exist and it ensures that no duplicate or repeated values are allowed.

Composite index is called as the one clustered index which is present on the multiple columns. Insert and update operation is slow down in this index.

NON-CLUSTERED INDEX:

It is the kind of the special type of index in which the logical order of the index does not get match with the physical stored rows on disk. It contains the pointer which points the index no in the memory space.
Index number will be increased each time when new records are inserted in the table. Database engine automatically creates this index, when the table is created with an unique key constraint. It does not store the data permanently on the disk.
It is just like the book index. Book indexes contain chapter name and page number.

 In order to read particular topic or chapter, you need to go through particular chapter name page number. There is no need to go through each and every page number. Data and index are not stored in the same place or location. In other words,they are having another place or location.Since,data and non-clustered index are stored separately, multiple non-clustered index in the table.

DIFFERENCE:


Clustered Index

Non-clustered Index

It is faster than non-clustered index.

It is slower than the clustered index.

Less memory is required to execute the operation.

More memory is required to execute the operation.

Ability to store the data on the disk naturally.

It does not have the data to store on the disk naturally.

Data sheets are stored in the leaf nodes.

Data sheets are not stored in the leaf nodes.

It is the main data.

Index is the main data.

Leaf nodes are itself actual data.

Leaf nodes are not itself actual data. Instead, it contains the multiple columns.

Clustered key will define the order of the data within the table.

Index key will define the order of the table within the index.

By default, primary key of the table is said to be clustered index.

Composite key used with the unique constraint of the table act as the non-clustered index.

It is more prefer for static data environments.

It is more prefer for dynamic data environments.

It contains an index id which is equal to zero.

It contains an index id which is greater than zero.


Comments

Popular posts from this blog

Difference between union and union all in oracle sql plsql

"This is one of the most important questions that interviewer might be asking in an interview.Infyosis,Linked group,Kyndryl,Vodafone Idea,IBM and Mphasis etc" INTRODUCTION: It is said to be set operators which is used to combine, add or concatenate two or more result sets. It is used in the multiple select statements where to combine to produce the final desired results.In other words,multiple select statements of similar column name in same order and having same data type to produce the unified result.In MIS datalake,when you are adding the modules of GST reconciliation which is to be used in micros in Excel or VB script, union and union all set operator is preferred for eliminating duplicate records or keeping duplicate records as per business requirement. Column must be of the same datatype for these operations of one select statement with another select statements. Columns must be in the same order in this set operators in the multiple select statements. Same number of co

Difference between decode and case oracle sql plsql interview question and answer

" This is the most accepted question for PLSQL developer role.It has been asked in many interviews like Mphasis and Kyndryl. "  INTRODUCTION: Case was came after oracle database version 8.1.6 whereas decode was came before oracle database version 8.1.6 .Decode and case statements in an oracle work or acts like if then elsif conditional statements. if sal='2000000' then 'General Manager' elsif sal='3000000' then 'Senior Manager' elsif sal='1200000' then 'Manager' else 'Employee' end if; create table student_details(Student_RollNo Number,Student_Name Varchar2(20),student_marks Number,student_result varchar2(1)); insert into student_details values (100,'Rahul',90,'P'); insert into student_details values (101,'Rakesh',30,'F'); insert into student_details values (102,'Ram',60,'P'); insert into student_details values (103,'Rohan',10,'F'); insert into student_detai

Difference view and Materialized view in Oracle SQL PLSQL Interview Question and Answer.

 " This is excepted question in oracle interview. It is asked in oracle technical support,PLSQL developer, SQL Analyst and SQL developer. " INTRODUCTION: View and Materialized view are called as the database object or the named query. View is the virtual table which stores the select statement from the base table by execution of the sql query at the runtime. View Query is running for the view definition. In the case of the materialized view, the data from the base table is loaded in the temporary or physical memory location by which the materialized view gets refreshed and all the dependent tables on the materialized view are also get updated after refresh operation. Materialized views are used in lakhs lines of code. In the data lake, tables are dependent on the master table to get updated where more than lakhs line of codes, today every reporting is based on this, in that case materialized view are used and preferred on the master tables. An activity of materialized view wi