473,246 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

What is the best way for storing lengths in a database?


Forgive me this stupid question, but what is the best way to store the
length of an object in a database? What datatype would you use? Would
it be better to define one of your own?

Nov 12 '05 #1
2 1405
Probably an INTEGER or a BIGINT that is NULLable. For convenience, you
might use the LENGTH function to calculate the length of such objects,
and use a standard data type that can handle any possible value returned.

Example:

select length(col1), length(col2), length(col3), length(col4) from
testdec

1 2 3 4
----------- ----------- ----------- -----------
13 13 9 9

1 record(s) selected.

Details of the LENGTH function from the SQL Reference manual:

"The LENGTH function returns the length of a value.

The argument can be an expression that returns a value of any built-in
data type.

The result of the function is a large integer. If the argument can be
null, the result can be null; if the argument is null, the result is the
null value.

The result is the length of the argument. The length does not include
the null indicator byte of column arguments that allow null values. The
length of strings includes blanks but does not include the length
control field of varying-length strings. The length of a varying-length
string is the actual length, not the maximum length.

The length of a graphic string is the number of DBCS characters. The
length of all other values is the number of bytes used to represent the
value:

2 for small integer
4 for large integer
(p/2)+1 for decimal numbers with precision p
The length of the string for binary strings
The length of the string for character strings
4 for single-precision floating-point
8 for double-precision floating-point
4 for date
3 for time
10 for timestamp"

Pekka Henttonen wrote:
Forgive me this stupid question, but what is the best way to store the
length of an object in a database? What datatype would you use? Would
it be better to define one of your own?


Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
3
by: Irene | last post by:
Hi all, I have set up a simple VB program (and later on an ASP interface) to manage an Athletics database. I'm using Access 2000. To simplify, I have the Athlets, the Competitions and the...
6
by: Peter Hickman | last post by:
I have a program that requires x strings all of y length. x will be in the range of 100-10000 whereas the strings will all be < 200 each. This does not need to be grown once it has been created....
17
by: | last post by:
I have an app that retrieves data from an Access database. At the moment I have the SQL string as a Const in my app. I understand this is not best practice. I don't want the user to have access to...
0
by: kid4rilla | last post by:
I can successfully write the binary data to an image data type, and successfully retrieve it, but when I attempt to play the file in media player after retrieving it, I get the file type isn't...
1
by: serge | last post by:
Right now the database I am working with is storing time in an Integer data type and is storing the time value in seconds. The application does not allow entering seconds. It accepts minutes and...
39
by: windandwaves | last post by:
Hi Folk I have to store up to eight boolean bits of information about an item in my database. e.g. with restaurant drive-through facility yellow windows
0
by: nass | last post by:
hello everyone and happy new year. i am not sure how to tackle this problem or where is originates from so i am writing here in hope that if you can not help you can at least point me in a...
5
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
Hi, I need to store lots of product images. I was thinking of storing the paths in the database but overtime it may become cumbersome as I'll be dealing with lots of images. I would need to...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.