View previous topic :: View next topic |
Author |
Message |
selva21 Beginner
Joined: 30 Dec 2003 Posts: 53 Topics: 31
|
Posted: Thu Jan 08, 2004 4:00 am Post subject: To write Better SQL statements. |
|
|
Hi,
I am in the process of consolidating tips on writing better SQL statements to improve the performance.
If you have something to add, please let me know.
Here are few.
Guideline for using a SELECT statement:
Specify only needed columns
Limit the number of rows by using predicates
Specify the FOR UPDATE clause if applicable
Specify the OPTIMIZED FOR n ROWS clause
Specify the FETCH FIRST n ROS ONLY clause
Specify the FOR FETCH ONLY clause if applicable
Avoid numeric data type conversion if required
Guidelines when choosing a data type
Use Character (CHAR) rather than varying-length data type for short columns
Use VARCHAR of VARGRAPHIC rather than LONG VARCHAR or LONG VARGRAPHIC.
Use Integer (SMALLINT, INTEGER,BIGINT) rather than floating point number (REAL or DOUBLE) or decimal (DECIMAL ) if you do not need to have the fraction part.
Use date-time (DATE,TIME,TIMESTAMP) rather than character (CHAR).
Use numeric data types rather than character.
Thanks and Regards,
A.Selvakumaran. _________________ --------------------------------------------------------
Knowledge is power. But Imagination is more important than Knowledge. -Albert Einstein
-------------------------------------------------------- |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
selva21 Beginner
Joined: 30 Dec 2003 Posts: 53 Topics: 31
|
Posted: Thu Jan 08, 2004 7:54 am Post subject: |
|
|
Thanks Kolusu ! _________________ --------------------------------------------------------
Knowledge is power. But Imagination is more important than Knowledge. -Albert Einstein
-------------------------------------------------------- |
|
Back to top |
|
 |
bauer Intermediate
Joined: 10 Oct 2003 Posts: 317 Topics: 50 Location: Germany
|
Posted: Thu Jan 15, 2004 1:51 pm Post subject: |
|
|
refer to IBM manuals, check the chapters for then EXPLAIN Command, you will find some additional tips. |
|
Back to top |
|
 |
|
|