Join a SELECT-Statement with a INDEX
can I force a SELECT-Statement to use a certain Table-INDEX?
f.e.
select * from table a
where a.key like '%p'
..forced index a.idx.--
Yes. You can.
Use SQL hint.
select /*+ index (tablename indexname) */.
If the index is usable-Oracle will use it. If not -Oracle will see it as a remark.
Similar Messages
-
What is syntax for inner join of Select statement with Secondary Index
Hi Genies,
Here i have created the Secondary index for table COEP and also used for select query but there is no improvement in runtime . taking same time for select query without index as well as with index. my code is
SELECT * INTO CORRESPONDING FIELDS OF TABLE ITAB_COEP FROM COEP AS A
INNER JOIN COBK AS B ON ( A~BELNR = B~BELNR AND A~KOKRS = B~KOKRS AND A~GJAHR = B~GJAHR )
WHERE A~OBJNR = OBJNR
AND A~GJAHR = CURRY
AND B~GJAHR = CURRY
AND A~RBEST = ''
AND A~BEKNZ = 'S'
AND B~BELNR NE WA_COBK-BELNR
AND B~AWREF_REV = ''
AND B~AWORG_REV = ''
AND B~KOKRS = WA_COIOB-KOKRS
AND B~BLDAT BETWEEN START_DATE AND END_DATE
AND B~BLART IN ('SA','KA','KR','AB') %_HINTS ORACLE 'INDEX("COEP" "COEP~ZBU")'.
index name is ZBU.
please any one let me know is there any syntax mistakes? but while checking and during the runtime it does'nt shows any error.
Regards,
Thangam.PHi Genies,
Here i have created the Secondary index for table COEP and also used for select query but there is no improvement in runtime . taking same time for select query without index as well as with index. my code is
SELECT * INTO CORRESPONDING FIELDS OF TABLE ITAB_COEP FROM COEP AS A
INNER JOIN COBK AS B ON ( A~BELNR = B~BELNR AND A~KOKRS = B~KOKRS AND A~GJAHR = B~GJAHR )
WHERE A~OBJNR = OBJNR
AND A~GJAHR = CURRY
AND B~GJAHR = CURRY
AND A~RBEST = ''
AND A~BEKNZ = 'S'
AND B~BELNR NE WA_COBK-BELNR
AND B~AWREF_REV = ''
AND B~AWORG_REV = ''
AND B~KOKRS = WA_COIOB-KOKRS
AND B~BLDAT BETWEEN START_DATE AND END_DATE
AND B~BLART IN ('SA','KA','KR','AB') %_HINTS ORACLE 'INDEX("COEP" "COEP~ZBU")'.
index name is ZBU.
please any one let me know is there any syntax mistakes? but while checking and during the runtime it does'nt shows any error.
Regards,
Thangam.P -
How to avoid data repetation when using select statements with innerjoin
how to avoid data repetation when using select statements with innerjoin.
thanks in advance,
satheeshyou can use a query like this...
SELECT DISTINCT
frg~prc_group1 "Product Group 1
frg~prc_group2 "Product Group 2
frg~prc_group3 "Product Group 3
frg~prc_group4 "Product Group 4
frg~prc_group5 "Product Group 5
prc~product_id "Product ID
txt~short_text "Product Description
UP TO 10 ROWS
INTO TABLE l_i_data
FROM
Joining CRMM_PR_SALESG and
COMM_PR_FRG_ROD
crmm_pr_salesg AS frg
INNER JOIN comm_pr_frg_rod AS prd
ON frgfrg_guid = prdfragment_guid
Joining COMM_PRODUCT and
COMM_PR_FRG_ROD
INNER JOIN comm_product AS prc
ON prdproduct_guid = prcproduct_guid
Joining COMM_PRSHTEXT and
COMM_PR_FRG_ROD
INNER JOIN comm_prshtext AS txt
ON prdproduct_guid = txtproduct_guid
WHERE frg~prc_group1 IN r_zprc_group1
AND frg~prc_group2 IN r_zprc_group2
AND frg~prc_group3 IN r_zprc_group3
AND frg~prc_group4 IN r_zprc_group4
AND frg~prc_group5 IN r_zprc_group5.
reward it it helps
Edited by: Apan Kumar Motilal on Jun 24, 2008 1:57 PM -
I m trying to find if LIMIT is a part of the select statement and if works like
set rowcount 1 in sybase....if anyone can post the generic select statement with LIMIT in it that would be great!
any help or input will be greatly appreciated
Thanks!Hallo,
i don't know sybase, but it is probably rownum
select * from scott.emp
where rownum < 3
Regards
Dmytro -
A Select statement with Appending table statement in it.
Hi,
How can I use a select statement with a <Appening table> statement in it.
SELECT DISTINCT <field Name>
FROM <DB table name>
APPENDING TABLE <itab>
WHERE <fieldname> EQ <Itab1-fieldname>
AND <fieldname> EQ <itab2-fieldname>.
Can I use the above select statement.If I'm using this...how this works?
Regards
DharmarajuHi, Dharma Raju Kondeti.
I found this in the SAP online help, hope this can help you.
Specifying Internal Tables
When you read several lines of a database table, you can place them in an internal table. To do this, use the following in the INTO clause:
SELECT ... INTO|APPENDING [CORRESPONDING FIELDS OF] TABLE <itab>
[PACKAGE SIZE <n>] ...
The same applies to the line type of <itab>, the way in which the data for a line of the database table are assigned to a table line, and the CORRESPONDING FIELDS addition as for flat work areas (see above).
The internal table is filled with all of the lines of the selection. When you use INTO, all existing lines in the table are deleted. When you use APPENDING; the new lines are added to the existing internal table <itab>. With APPENDING, the system adds the lines to the internal table appropriately for the table type. Fields in the internal table not affected by the selection are filled with initial values.
If you use the PACKAGE SIZE addition, the lines of the selection are not written into the internal table at once, but in packets. You can define packets of <n> lines that are written one after the other into the internal table. If you use INTO, each packet replaces the preceding one. If you use APPENDING, the packets are inserted one after the other. This is only possible in a loop that ends with ENDSELECT. Outside the SELECT loop, the contents of the internal table are undetermined. You must process the selected lines within the loop.
Regards,
feng.
Edited by: feng zhang on Feb 21, 2008 10:20 AM -
How to compile the hint to force selection statement to use index
Hello expert,
will you please tell me how to compile the hint to force selection statement to use index?
Many Thanks,Not sure what you mean by compile, but hint is enclosed in /*+ hint */. Index hint is INDEX(table_name,index_name). For example:
SQL> explain plan for
2 select * from emp
3 /
Explained.
SQL> @?\rdbms\admin\utlxpls
PLAN_TABLE_OUTPUT
Plan hash value: 3956160932
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 14 | 546 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| EMP | 14 | 546 | 3 (0)| 00:00:01 |
8 rows selected.
SQL> explain plan for
2 select /*+ index(emp,pk_emp) */ *
3 from emp
4 /
Explained.
SQL> @?\rdbms\admin\utlxpls
PLAN_TABLE_OUTPUT
Plan hash value: 4170700152
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 14 | 546 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMP | 14 | 546 | 2 (0)| 00:00:01 |
| 2 | INDEX FULL SCAN | PK_EMP | 14 | | 1 (0)| 00:00:01 |
9 rows selected.
SQL> Hint in the above example is forcing optimizer to use index which resul;ts in a bad execution plan. Most of the time optimizer does not need hints and chooses an optimal plan. In most cases sub-optimal plan is result of stale or incomplete statistics.
SY. -
Hi,
If SELECT statement has IN in the where clause, does that use the index?
For example,
SELECT t1 f2 f4 from ztest
WHERE
fid IN s_id AND
doctype IN s_doctype AND
year IN s_year .
What is the other option to optimize the SELECT with IN?
Thanks & regards,
YogitaModerator message - Please search before asking - post locked
Rob -
How to use a select statement with chinese characters?
I am currently developing a java servlet<using tomcat 4.x> which allows me to use select statement to retrieve results from the Microsoft SQL Server 2000 database. I am using a simple form to get the parameter for querying. The main problem i'm facing is that there are chinese information in the SQL database, but i can't retrieve it through the sql statement with the chinese characters input<thru the form with the help of NJ STAR>in the WHERE condition. When i execute the statement, it returns me no results even though the rows are present in the database.
Does anyone have the solution to using chinese words in the WHERE clause of the select statement to retrieve results with columns which contains chinese characters? Please help me. Thanks everyone. :)
PS: when i cut and paste those characters in the sql database and paste onto java.. it is ??? in questionmarks.. but when i paste them into excel 2000.. its shown as chinese chars again..
please heelppp~~Greetings,
PS: when i cut and paste those characters in thesql
database and paste onto java.. it is ??? in
questionmarks.. but when i paste them into excelThis is why the SELECT is not returning any results.
You need to set the character encoding set on your
statement and parameters for the characters to be
properly translated. Refer to the charsetName
parameter in the String class constructor in your API
docs and also to
$JDK_DOCS/guide/intl/encoding.doc.html in your JDK
documentation.
2000.. its shown as chinese chars again..Because Office programs are performing the same kind
of character translation with the appropriate MS APIs.
please heelppp~~Regards,
Tony "Vee Schade" Cookis it possible for you to show me some coding examples? i don't really understand what is to be done in order to set the char set and what does it really do.. tried reading up but still dun understand.. :(
pardon my shallow knowledge of java..
ok..
The thing is when i used an insert statement with chinese characters of GBK format hardcoded into the java servlet and then i use the insert statement to insert the chars into the database, it cannot be seen as a chinese word when i off the NJStar. and then it can be searched out with my current form of servlet.. below is my coding of the servlet..
note: i've set my html file to charset = GBK
//prototype of Search engine...
//workable for GBK input and output...
import java.io.*;
import java.io.OutputStream;
import java.io.IOException;
import javax.servlet.http.*;
import javax.servlet.ServletException;
import java.util.*;
import java.sql.*;
import java.nio.charset.Charset;
public class SearchBeta extends HttpServlet {
private Vector musicDetails = new Vector();
private String query = "";
public void service (HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException, UnsupportedEncodingException {
query = req.getParameter ("T1");
System.out.println("before:"+query);
String type = req.getParameter ("D1");//type
query = req.getParameter ("T1");
//query = "������";
System.out.println("after:"+query);
getResults(type,query);
System.out.println("locale = :"+req.getLocale());
res.setContentType ("text/html;charset=GBK");
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<body bgcolor = \"black\">");
out.println("<font face = \"comic sans ms\" color=\"Cornsilk\">");
if (query.length()==0)
out.println ("Please key in your search query.");
else if (musicDetails.size()==0)
out.println ("Sorry, no results matching your search can be found.");
else {
out.println("<center>");
out.println("<table cellspacing = \"50\">");
int i = 0;
//Display the details of the music
while (i<musicDetails.size()) {
Results details = (Results)musicDetails.get(i);
String dbArtist = "";
String dbAlbum = "";
String dbTitle = "";
String dbCompany = "";
dbAlbum = details.getAlbum();
dbTitle = details.getTitle();
dbCompany = details.getCompany();
dbArtist = details.getArtist();
try{
dbAlbum = new String(dbAlbum.getBytes("ISO-8859-1"),"GBK");
dbTitle = new String(dbTitle.getBytes("ISO-8859-1"),"GBK");
dbCompany = new String(dbCompany.getBytes("ISO-8859-1"),"GBK");
dbArtist = new String(dbArtist.getBytes("ISO-8859-1"),"GBK");//correct translation.
catch(UnsupportedEncodingException e){
System.out.print(e);
e.printStackTrace();
String dbImage_loc = details.getImage();
out.println("<tr>");
out.println("<td><table>");
out.println("<img src=C:\\Program Files\\Apache Group\\Tomcat 4.1\\webapps\\examples\\ThumbNails\\"+dbImage_loc+">");
out.println("<tr>");
out.println("<th><font color=\"violet\"> Artist: </font></th>");
out.println("<td><font color=\"Cornsilk\">"+dbArtist+"</font></td>");
out.println("</tr>");
out.println("<tr>");
out.println("<th><font color=\"violet\"> Title: </font></th>");
out.println("<td><font color=\"Cornsilk\">"+dbTitle+"</font></td>");
out.println("</tr>");
out.println("<tr>");
out.println("<th><font color=\"violet\"> Company: </font></th>");
out.println("<td><font color=\"Cornsilk\">"+dbCompany+"</font></td>");
out.println("</tr>");
System.out.println("album: "+ dbAlbum);
out.println("<tr>");
out.println("<th><font color=\"violet\"> Album: </font></th>");
out.println("<td><font color=\"Cornsilk\">"+dbAlbum+"</font></td>");
out.println("</tr>");
System.out.println("company: "+ dbCompany);
out.println("</table></td>");
out.println("</tr>");
i++;
out.println("</table>");
out.println("</center>");
out.println("</font>");
out.println("</body>");
out.println("</head>");
out.println("</html>");
out.close();
//to remove all the elements from the Vector
musicDetails.removeAllElements();
//get Searched Music Details and store in Results object which is stored in musicDetails vector
public void getResults (String type, String searchQuery) {
try {
Class.forName ("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=music","sa","kokkeng");
Statement stmt = con.createStatement();
String query = "SELECT * FROM MusicDetails WHERE "+type+" = '"+searchQuery+"'";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String artist = rs.getString("Artist");
String title = rs.getString("Song");
String company = rs.getString("Company");
String album = rs.getString("Album");
String image_loc = rs.getString("Image");
Results details = new Results (artist,title,company,album,image_loc);
musicDetails.add(details);
stmt.close();
con.close();
catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
with the above servlet i created, i can search out the data in the database which i've inserted through the insert statement. I still can't search for things i've keyed into the database directly using NJStar..
thank you so much for helping.. really hope any one else who knows the answer to this will reply too... thank you all so much...
-KK -
Incorrect SELECT statement with single quotes
I am getting the following error trying to select a value from a database:
SQLException caught: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'mod='Payroll''. Couldn't load driver:[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'mod='Payroll''.
Here is the select statement code:
PreparedStatement ps = con.prepareStatement("SELECT username FROM experts WHERE mod='"+mod+"'");
I have tried all kinds of variations with the quotes, and single quotes but still get the same error...I know I'm on the right track but I can't seem to spot the error and was hoping someone else could??
thanks in advance,
chukHi,
I tried that and now I get an even stranger syntax error which says "Syntax error (missing operator) in query expression 'mod=Pa_RaM000'."
any ideas? -
Inner join in select statement
hi,
i am using select statement like
SELECT ekkoebeln ekkobukrs ekkobstyp ekkobsart ekko~ernam
ekkolifnr ekkozterm ekkozbd1t ekkozbd2t ekko~zbd3t
ekkozbd1p ekkozbd2p ekkoekorg ekkoekgrp ekko~waers
ekkowkurs ekkokufix ekkobedat ekkokdate
Begin of Changes, RICEF : 293.
ekkozzhedg ekkozzheda ekkozzpba ekkozzpbubu lfa1~vbund
End of Changes, RICEF . 293.
lfa1land1 lfa1name1
ekpa~lifn2
INTO CORRESPONDING FIELDS OF TABLE iekko
FROM ekko
JOIN lfa1 ON lfa1lifnr = ekkolifnr
LEFT JOIN ekpa ON ekpaebeln = ekkoebeln AND
ekpa~ebelp = '00000' AND
ekpa~parvw = 'RS'
FOR ALL entries IN icooi
WHERE ekko~ebeln = icooi-refbn
AND ekko~zzhedg IN s_zzhedg
AND ekko~zzheda IN s_zzheda.
where in ekko table ,the fields zzhedg and zzheda are appended..but in the debugging mode i am unable to see this 2 field....in the output also....so how should i write my select query?Hi,
Is your select statement returning sy-subrc 0. In debugging mode may be your fields may not be visible in the screen since your internal table has many fields, you have to press >> forward button to check the fields.
Thanks & Regards,
Navneeth K. -
Default join in select statements
Hi guyz,
If I am using just Join in my select statement. What does it do by default
1. innter join
2. outer join
eg:
select vbeln posnr into table itab from vbak <b>join</b> vbap on vbakvbeln = vbapvbeln.
Thanks.Mgs,
By Default innerjoin.
See the diff.
Hi karan check also the "left outer join" statement.
It might help you if you need 1-N relation
// left outer Join
Table 1 Table 2
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
3
e2
f2
g2
h2
a3
b3
c3
2
4
e3
f3
g3
h3
a4
b4
c4
3
|--|||--|
Left Outer Join
|--||||||||--|
| A | B | C | D | D | E | F | G | H |
|--||||||||--|
| a1 | b1 | c1 | 1 | 1 | e1 | f1 | g1 | h1 |
| a2 | b2 | c2 | 1 | 1 | e1 | f1 | g1 | h1 |
| a3 | b3 | c3 | 2 |NULL|NULL|NULL|NULL|NULL|
| a4 | b4 | c4 | 3 | 3 | e2 | f2 | g2 | h2 |
|--||||||||--|
// Inner Join
Table 1 Table 2
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
3
e2
f2
g2
h2
a3
b3
c3
2
4
e3
f3
g3
h3
a4
b4
c4
3
Inner Join
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
1
e1
f1
g1
h1
a4
b4
c4
3
3
e2
f2
g2
h2
Pls. mark if useful -
Hi All,
I have 9 select Statements,i can combine these queries by 'UNION' to get the result....but the process will be tedious.
Is there any other option to do the same in a easy way.
Example :
SELECT ecv.creation_date "Initiation Date",
eceb.c_ext_attr1 "REPORTING PERSON",
eceb.c_ext_attr2 INITIATOR,
eceb.c_ext_attr3 "REPORTING PERSON TITLE",
eceb.d_ext_attr2 "AWARE DATE",
eceb.c_ext_attr4 TELEPHONE
FROM eng_changes_v ecv,
eng_changes_ext_b eceb
WHERE ecv.change_id = eceb.change_id
AND ecv.change_notice = 'COM-10034'
AND attr_group_id = 266;
UNION
SELECT eceb.c_ext_attr2 TYPE,
eceb.c_ext_attr3 INSTITUTION,
eceb.c_ext_attr4 TERRITORY,
eceb.c_ext_attr5 "CUSTOMER NAME",
eceb.c_ext_attr6 TITLE,
eceb.c_ext_attr7 ADDRESS,
eceb.c_ext_attr8 "ADDRESS 2",
eceb.c_ext_attr9 CITY,
eceb.c_ext_attr10 STATE,
eceb.n_ext_attr1 ZIP,
eceb.c_ext_attr11 COUNTRY,
eceb.c_ext_attr12 TELEPHONE,
eceb.c_ext_attr13 FAX
FROM eng_changes_v ecv,
eng_changes_ext_b eceb
WHERE ecv.change_id = eceb.change_id
AND ecv.change_notice = 'COM-10034'
AND attr_group_id = 267;
In this fashion i have 9 select statements.
Thanks in advance!
RamyaWell, this is not the silly EAV model …
but it does look as something that has been slightly abused on the dynamic/generic side.
You certainly do not want to UNION … it wouldn’t make sense anyway.
Think of your ATTR_GROUP_ID as identifiers of what could have been real tables
(dependents of ENG_CHANGES_V):
create view could_be_table_266 as
select change_id
,c_ext_attr1 REPORTING_PERSON
,c_ext_attr2 INITIATOR
,c_ext_attr3 REPORTING_PERSON_TITLE
,d_ext_attr2 AWARE_DATE
,c_ext_attr4 TELEPHONE
from eng_changes_ext_b
where attr_group_id = 266
create view could_be_table_267 as
select change_id
,c_ext_attr2 TYPE
,c_ext_attr3 INSTITUTION
,c_ext_attr4 TERRITORY
,c_ext_attr5 CUSTOMER NAME
,c_ext_attr6 TITLE
,c_ext_attr7 ADDRESS
,c_ext_attr8 ADDRESS_2
,c_ext_attr9 CITY
,c_ext_attr10 STATE
,n_ext_attr1 ZIP
,c_ext_attr11 COUNTRY
,c_ext_attr12 TELEPHONE
,c_ext_attr13 FAX
from eng_changes_ext_b
where attr_group_id = 267
Then join using your knowledge of what the “logical” relationship between these table would be … likely
select <columns_you_need_from x>
,<columns_you_need_from a>
,<columns_you_need_from b>
from eng_changes_v x
,could_be_table_266 a
,could_be_table_267 b
where x.change_id = a.change_id (+)
and x.change_id = b.change_id (+)
and x.change_notice = 'COM-10034'
Using column names like "REPORTING PERSON" rather than REPORTING_PERSON is just a pain in the …
What column headings one wants in a report/screen doesn’t have to drive the names of select list items in SQL.
TYPE is likely not a good name … reserved word -
How to speed a select statement with the NOT EXISTS where condition ?
Hi all,
I created a view : create or replace view view_name as select * from table_1,table_2 where join_condition and some conditions.
Now I have added in the view "where" clause two NOT EXISTS conditions based on one another different table respectively.
Before I added these two conditions the response time was fast ; but after I added these two conditions then the response time deteriorated.
So how to optimize the select statement ? Hints and so on ...
Thank you very much indeed
Message was edited by:
andrianiainaJust run the script :
SQL> explain plan for select * from dual;
Explained.
SQL> @$ORACLE_HOME/rdbms/admin/utlxpls.sql
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | | | |
| 1 | TABLE ACCESS FULL | DUAL | | | |
Note: rule based optimization
9 rows selected.
SQL>Nicolas. -
Select query with secondary index
hi,
i have a report which is giving performance issues on a perticular select query on KONH table.
the select query doesnt use the primary key fields and table already has around 19 million entries.So there was a secondary index created for the fields in the table.
now, KONH is a client specific table, and hence has MANDT as the first field. when the table is not indexed it is sorted according to the order of fields, like first MANDT, then primary key fields and then remaining fields.. (correct me if i am wrong)
but the secondary index created doesnt has MANDT in it..(yea, a mistake! )...
but instead of correccting the secondary index, i am told to change the select query..
so, i used a "client specific" syntax to sort the issue.. but i dont understand whre i should put the "where mandt eq sy-mandt" clause..
should i put it right after all my secondary index fields are over? or what happens to the order of fields which are not present in the list of secondary index?
kindaly help.
thanx.Hi chinmay kulkarni,
its better if you can ask concerned person to add MANDT field in your index as well....
Indexes and MANDT
If a table begins with the mandt field, so should its indexes. If a table begins with mandt and an index doesn't, the optimizer might not use the index.
Remember, if you will, Open SQL's automatic client handling feature. When select * from ztxlfa1 where land1 = 'US' is executed, the actual SQL sent to the database is select * from ztxlfa1 where mandt = sy-mandt and land1 = 'US'. Sy-mandt contains the current logon client. When you select rows from a table using Open SQL, the system automatically adds sy-mandt to the where clause, which causes only those rows pertaining to the current logon client to be found.
When you create an index on a table containing mandt, therefore, you should also include mandt in the index. It should come first in the index, because it will always appear first in the generated SQL.
Index: Technical key of a database table.
Primary index: The primary index contains the key fields of the table and a pointer to the non-key fields of the table. The primary index is created automatically when the table is created in the database.
Secondary index: Additional indexes could be created considering the most frequently accessed dimensions of the table.
Structure of an Index
An index can be used to speed up the selection of data records from a table.
An index can be considered to be a copy of a database table reduced to certain fields. The data is stored in sorted form in this copy. This sorting permits fast access to the records of the table (for example using a binary search). Not all of the fields of the table are contained in the index. The index also contains a pointer from the index entry to the corresponding table entry to permit all the field contents to be read.
When creating indexes, please note that:
An index can only be used up to the last specified field in the selection! The fields which are specified in the WHERE clause for a large number of selections should be in the first position.
Only those fields whose values significantly restrict the amount of data are meaningful in an index.
When you change a data record of a table, you must adjust the index sorting. Tables whose contents are frequently changed therefore should not have too many indexes.
Make sure that the indexes on a table are as disjunctive as possible.
(That is they should contain as few fields in common as possible. If two indexes on a table have a large number of common fields, this could make it more difficult for the optimizer to choose the most selective index.)
For Example...
SELECT KUNNR KUNN2 INTO TABLE T_CUST_TERR
FROM KNVP CLIENT SPECIFIED
WHERE MANDT = SY-MANDT " here MANDT shd be first
AND KUNN2 IN S_TERR
AND PARVW LIKE 'Z%'.
Accessing tables using Indexes
The database optimizer decides which index on the table should be used by the database to access data records.
You must distinguish between the primary index and secondary indexes of a table. The primary index contains the key fields of the table. The primary index is automatically created in the database when the table is activated. If a large table is frequently accessed such that it is not possible to apply primary index sorting, you should create secondary indexes for the table.
The indexes on a table have a three-character index ID. '0' is reserved for the primary index. Customers can create their own indexes on SAP tables; their IDs must begin with Y or Z.
If the index fields have key function, i.e. they already uniquely identify each record of the table, an index can be called a unique index. This ensures that there are no duplicate index fields in the database.
When you define a secondary index in the ABAP Dictionary, you can specify whether it should be created on the database when it is activated. Some indexes only result in a gain in performance for certain database systems. You can therefore specify a list of database systems when you define an index. The index is then only created on the specified database systems when activated
Also pls have a look on below link
http://www.sapfans.com/sapfans/forum/devel/messages/30240.html
Hope it will solve your problem..
Reward points if useful...
Thanks & Regards
ilesh 24x7 -
Generating SQL SELECT statement with Schema
I develop a 3rd-party application that connects to various
databases via ODBC. Our program generates the SQL statement
so that the user does not have to. When connecting to oracle the
user often gets the error message: ORA-00942: table or view does
not exist.
To work around this our tech support department has tells the
customer to enter in the Schema name before the table name.
Thus,
SELECT ItemNo from Item
becomes
SELECT ItemNo from MySchema.Item
Is there a way that I can query the Data Source to find out
the Schema name so that our program can put in in the
statement. Is there a SQLGetInfo call I can make to get
this information?
Or, should I have the Server specified in the connection
string? For SQL Server we use SQLGetPrivateProfileString to
obtain the server name and then include it in the connection
string: SRVR=<servername>
Unfortunately, if this is the case the keyword is different
depending on the ODBC Driver involved. "Server" for Microsoft.
"SRVR" for Intersolv. "ServerName" for Oracle.
Note: We do not have Oracle in-house to test with. I'm
wondering if we could get Oracle for free for development
purposes.
Any and all information would be greatly appreciated.Thanks for the tip. I just finished downloading Oracle.
One user is able to successfully view the database with the
statement:
SELECT ItemNo from Item
But if another user tries it he gets the "table or view not
found" message. Changing the statement as follows will allow
the 2nd user to view the database:
SELECT ItemNo from "MAXIMO".Item
I want my application to query the database via ODBC for the
"MAXIMO" string so I can create the correct SQL statement.
Thanks!
<<Are you trying to view tables from a non-default schema?>>I don't know. You would know better than me from my
description.
Maybe you are looking for
-
I have to use V3.5.10 despite wanting to run 3.6 (just updated to 3.6.6 too). However when I run 3.6 I hear thru my sounds set up a process open briefly and then close every 30 seconds or so - it's very regular and insistent and I'd like to know what
-
How do I put music that is on my laptop onto my Ipod nano 4th generation?
Im new to Apple products and the Apple web page itself. I ripped somemusic from my CDs onto my laptop and want to know how to put it all on my IPod Nano. I think it's a 4th generation. I greatly appreciate any good and helpful advice anyone has to of
-
Batch insert filename in textpath script crashes Illustrator
Hi everyone! First off: I am not a programmer. Just playing around with code and trying to get it to work for a specific task: Here is a script made for the purpose of inserting a text with the file name in over 600 pdf files. This is suppose to work
-
Itunes 10.7.0.21 on windows 7 64 bit
I installed the latest itunes version 10.7.0.21 on windows 7 64bit and now I cannot open itunes. Any suggestions?
-
Why won't raw images display as thumbnails in organiser?
My raw images display only as the 'egg timer' icons in Organiser. I can open them individually, edit and save as jpeg but cannot view them on the grid either before or after editing. This has only just started happening - two weeks ago all was well.