If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Determing rowsize

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-25-04, 03:19
banjoke banjoke is offline
Registered User
 
Join Date: Oct 2004
Posts: 5
Determing rowsize

Hi,

Im using a couple of db2 tables, but i want to find the size of one row.
It has some CHAR, FLOAT and DEC FIXED in there.

Is there a way to calculate how long the row is (by adding all columns)?

Thanx in advance
Regards
Reply With Quote
  #2 (permalink)  
Old 10-25-04, 04:05
Filip Poverud Filip Poverud is offline
Registered User
 
Join Date: Oct 2004
Location: Norway
Posts: 53
SELECT
RECLENGTH
FROM
SYSIBM.SYSTABLES
WHERE
NAME = 'NAMEOFTHETABLE';

---

/pF
Reply With Quote
  #3 (permalink)  
Old 10-25-04, 04:30
banjoke banjoke is offline
Registered User
 
Join Date: Oct 2004
Posts: 5
Hi,

the statement doesn't work, but i think it is because i use temporary db2 tables. but i think i can calculate the length myself, but i can't find the lenght that a float represents.

Regards
Reply With Quote
  #4 (permalink)  
Old 10-25-04, 05:18
Filip Poverud Filip Poverud is offline
Registered User
 
Join Date: Oct 2004
Location: Norway
Posts: 53
It really depends on whether you CREATE the temp table (Stored in Catalog) or DECLARE it (Not stored in Catalog).

---

/pF
Reply With Quote
  #5 (permalink)  
Old 10-25-04, 05:26
banjoke banjoke is offline
Registered User
 
Join Date: Oct 2004
Posts: 5
I declare the table, here is a small example.

DECLARE GLOBAL TEMPORARY TABLE tab1
(var1 float NOT NULL,
var2 char(16) NOT NULL,
var3 decimal (15,2) NOT NULL);

I think that the char(16) has a length of 16 and that decimal (15,2) has a length of 15 but i have no idea about the float.

regards
Reply With Quote
  #6 (permalink)  
Old 10-25-04, 05:52
Filip Poverud Filip Poverud is offline
Registered User
 
Join Date: Oct 2004
Location: Norway
Posts: 53
Well, it's rather more difficult than that.

Here is a link that basically describes how they are stored in v. 8.x:

http://publib.boulder.ibm.com/infoce...jnqmstr179.htm

---

/pF
Reply With Quote
  #7 (permalink)  
Old 10-25-04, 06:08
banjoke banjoke is offline
Registered User
 
Join Date: Oct 2004
Posts: 5
so if i have it correct

a float has length 8
a char(n) has length n
a decimal(15,2) has length 4

regards
Reply With Quote
  #8 (permalink)  
Old 10-25-04, 10:19
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
A decimal(15,2) has an internal length of 8. This is (n +1)/2, rounded to next highest number if not an integer value. So it is (15+1)/2 = 8.

DB2 integers have an internal length of 4. Small integers have an internal length of 2.

Don't forget to add one byte for all nullable columns, and 2 more bytes for any column defined as varchar. The space used by the varchar itself depends on the data in it, so you would have to estimate an average length.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390

Last edited by Marcus_A; 10-25-04 at 10:22.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On