Discussion:
varchar length
(too old to reply)
m***@bithology.nl
2007-08-31 08:49:39 UTC
Permalink
Hi,

I have this question from a customer:

When using varchar's in my table definitions I have to specify the maximum length. Why would I specify a different length for each column (Name varchar20, Street varchar30, Email varchar40) when I can simply define a varchar(255) for each column (not bothering about choosing lenghts)?

Is there a difference between the two regarding performance and storage?

Cheers,
Martin
Knut Stolze
2007-08-31 11:01:49 UTC
Permalink
Post by m***@bithology.nl
Hi,
When using varchar's in my table definitions I have to specify the maximum
length. Why would I specify a different length for each column (Name
varchar20, Street varchar30, Email varchar40) when I can simply define a
varchar(255) for each column (not bothering about choosing lenghts)?
In DB2, a single row must fit entirely on a database. Thus, if you choose
VARCHAR(255) for all VARCHAR columns, you may run into situations where the
total maximum possible row length would exceeds the size of the data page
and you could not create the table.

Something else to consider are application requirements. An application
will have to provide larger buffers when fetching data from the database.
While it does not matter for one row, it could become an issue if you
retrieve lots and lots of rows.
Post by m***@bithology.nl
Is there a difference between the two regarding performance and storage?
No, there is not.
--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Knut Stolze
2007-09-02 18:53:06 UTC
Permalink
Post by Knut Stolze
Post by m***@bithology.nl
When using varchar's in my table definitions I have to specify the
maximum length. Why would I specify a different length for each column
(Name varchar20, Street varchar30, Email varchar40) when I can simply
define a varchar(255) for each column (not bothering about choosing
lenghts)?
In DB2, a single row must fit entirely on a database.
That should have been "on a database _page_".
--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Mark A
2007-08-31 23:51:33 UTC
Permalink
Post by m***@bithology.nl
Hi,
When using varchar's in my table definitions I have to specify the maximum
length. Why would I specify a different length for each column (Name
varchar20, Street varchar30, Email varchar40) when I can simply define a
varchar(255) for each column (not bothering about choosing lenghts)?
Is there a difference between the two regarding performance and storage?
Cheers,
Martin
The maximum length should agree with what your application programs are
expecting and what they can handle.
Loading...