View previous topic :: View next topic
|
Author |
Message |
userarun
New User
Joined: 08 Sep 2006 Posts: 9
|
|
|
|
Hi all,
is it possible to fetch random rows in a table without knowing any information about table, you only know the name.
for example in a table MYTABLE display first , fifth, seventh rows.
If it is possible please let me know.
Also tell me that how to fetch a row in table using indexes.
Can we fetch a row using index created on primary key.
Arun. |
|
Back to top |
|
|
MFRASHEED
Active User
Joined: 14 Jun 2005 Posts: 186 Location: USA
|
|
Back to top |
|
|
userarun
New User
Joined: 08 Sep 2006 Posts: 9
|
|
|
|
@MFRASHEED
Thanks for that , this is the thing i 'm looking for.
FETCH ROWSET STARTING AT
ABSOLUTE 5 FOR 1 ROW
would this option return the fifth row of the table.
If u give me an example containing both declaring and fetching cursor then that would be best.
Also tell me that can we fetch any row using indexes?
with regards,
Arun |
|
Back to top |
|
|
MFRASHEED
Active User
Joined: 14 Jun 2005 Posts: 186 Location: USA
|
|
|
|
Quote: |
would this option return the fifth row of the table.
|
Looks like it will, try it out.
Quote: |
If u give me an example containing both declaring and fetching cursor then that would be best.
|
Links provided in previous post also have examples, just scroll down to the end of manual.
Quote: |
Also tell me that can we fetch any row using indexes?
|
If a table has index, Db2 will always try to use the index.
If a table has multiple indexes, Db2 optimizer will again try to use fastest path to access data. We need to make sure that Runstats,Reorg and Rebind are schedule to run depending to activity on table. Runstats keeps stats on table accurate and helps optimizer determine best/fastest path to data.
Probably good SQL coding practive would be to code the WHERE clause of SQL to have indexed column with '=' first, then index columns with >,<, or Between next, then non-indexed column's with '=' and non-indexed columns with <,> , Between etc.
To get any idea filtering and access path SQL would take, execute EXPLAIN or Enhanced Explain on SQL. |
|
Back to top |
|
|
userarun
New User
Joined: 08 Sep 2006 Posts: 9
|
|
|
|
@ MFRASHEED
Thanx for this help. This will help me a lot.
i'll contact u if get any problem. Thanx.
With regards,
Arun. |
|
Back to top |
|
|
|