Sie sind auf Seite 1von 7

INDEX Purpose : Index makes the data base searh faster.

How it works: Index can be considered as a copy of the database reduced to certain fields. The copy generated at the time of creation of index is always in sorted form which makes the search faster. This index table also contiains a field which contains the pointer to the actual record in the table. Types of Index: 1. Primary Index. 2. Secondary Index. Primary Index : 1. Primary index contains all the key fields of the table and a pointer to the non key fields. 2. It is automatically created at the time of creation of table. Let us take an example table scounter. The structure of the table is as shown below.

The primary index created at the time of creation of table will contains all the primary key and a pointer to the non key fields. The primary index table will contains field like mandt carrid countnum and pointer in an sorted order.

The above example demonstrates how the primary index table will look like and the pointer referes to position where the same record in the sorted primary table is available in the actual database table which you can see with the highlighted Red line. Secondary Index: We can also add our own index to the table known as secondary index. We create secondary index for the non key fields. The secondary index are only to be created when these fields are used extensively in search. In the above mentioned table consider an scenario where I wanted to fetch the record from the database based on the airport code which is actually an non key field. Sorting of the primary keys will not be of any use as the airport code will still be scattred. A secondory index for the field airtport code needs to be created to support the faster access.

Creating a secondary index: Step 1: Go to the Tcode SE11. Enter the table name and choose display mode.

Step 2: Click on the indexes button.

Step 3 : Click on the create index button.

Step 4: Enter the name for the index in the popup and press enter.

Step 5: Enter the short description and the field name in the displayed screen,

Save and activate. The secondary index for the field airport is now created. The structure of the secondary index which we created now will contain mandt airport and pointer column which will be in the sorted form as shown below.

Now when I select the records using the airport code, Then the system will identify the list of records for the airport code in the index table and fetch the corresponding records using the pointer which you can see through the highlighted color red for the airport search LCY. There are two types of secondary indexes. 1. Non-Unique Index 2. Unique Index Which you can choose through option

Unique Index: An entry in an index can refer to several records that have the same values for the index fields. A unique index does not permit these multiple entries. The index fields of a unique index thus have key function, that is they already uniquely identify each record of the table. The primary index of a table is always a unique index since the index fields form the key of the table, uniquely identifying each data record. Suppose if I create the index as an Unique index for the field airport then the system will not allow the duplication of the record similar to LCY highlighted in the red in the secondary index table. The usee of Unique index does not influence the speed, it simply means that certain combinations of the fields in the table are unique. Note : A unique index for client dependent table must contain the field mandt. The optimizer of the database decides whether the index has to be used for search so index may only result in gaining the performance.

Key Points when creating the secondary index. * The first field in the index must be the one which have constant value for the large number of selections. Suppose if I have four fields in the index field1 field2 field3 and field4 for the table TABLE then field1 has more constant values than other fields. My index table structure will be like field1, field2, field3 field4 and pointer in a sorted form by the four fields and I specify a select query like. Select * from table TABLE into table IT_TABLE where field1 = condition and Field2 = condition and field4 = condition. Since the third field of the index has not been mentioned, sorting the index table only to two fields will be of use. The system will selected the set of records for the field1 and field2 quickly and then finds the record for the field4 from the selected set.

* Only those fields that significantly restrict the set of results in a selection are rational for an index. Example: Suppose if I create an index for the address table ADRTAB with fields tile, first name and last name and if I write my select query like. Select * from adrtab into table it_adrtab where title = Mr and first name = X and last name = Y. Since there wont be many peoples with the same name and same title, it is not sensible to create a index in a combination like this where as title can be considered as there will be may people with the same title.

Das könnte Ihnen auch gefallen