Jump to content

Understanding Length/Values a little more


Recommended Posts

Hey,

 

I have a question about the Length/Value option that is available through MySQL.

 

If I use `ID` and set the type to INT and 255 length/value, does that mean it will go up to 255 digits like so:

 

1,2,3...134...212...255

 

With different inputs in each and then reset back to 1 or whatever is available? Or what happens when it finally reaches 255 length?

So an INT  can hold about 2147483648(give or take a few) inputs before it runs out?

 

The length of fields is limited by... the field length.

 

The field length of an HTML page? Or do you mean the the length within SQL. So if I do varchar(255), and I input into it a 255 characters it will stop there and not allow any more?

Oh yeah, on var fields, the var means variable, and the length is the maximum length.

 

 

I was thinking length of numeric fields.

 

So an INT  can hold about 2147483648(give or take a few) inputs before it runs out?

 

 

The highest value an integer field (signed) can hold is 2^31-1.

[tex]2 ^{32-1} = 4294967295 = 11111111111111111111111111111111[/tex] in binary

That's 32 ones just to keep you from counting them

That is what is known as a 32 bit unsigned integer.

 

[tex]2 ^{31-1} = 2147483647 = 01111111111111111111111111111111[/tex] in binary

That's 31 ones just to keep you from counting them

That is what is known as a 32 bit signed integer. *note the preceding zero

 

The signed part of it means....that the zero is used to determine if the number is negative or positive.....I'm not too sure about which is positive or negative...0 or 1, but that's the idea of it.  I maybe completely wrong about this part though...don't take my word on it......but I know there is a dedicated bit somewhere

 

 

VARCHAR is different...if you give it a value of 255 characters....there is no binary aspect to that.....that straight up means.....255 characters.

 

EDIT: More reading if you need it

http://en.wikipedia.org/wiki/Integer_(computer_science)

Thanks for the wiki. In addition to what I already said, I was also trying to ask if the ID(INT) is incremented automatically it will do so until whatever value I set it to? Meaning if ID is 50 then it will do:

 

1

2

3

..

50

 

then reset? or just not allow anything? or throw an error?

you can't ...."set" a custom length on an INT...at least I don't think you can..but either way

if you have a 8 bit ID (int)...that is autoincrementing.....it will...yes...throw an error after a while.. ONLY IF THE FIELD IS A PRIMARY KEY THOUGH

 

There error will be a duplicate entry error. So when you get to ID 128...or what is supposed to be 128....you can't do it, because 127 is the max on an 8-bit INT ... unsigned.

 

 

In short...there is no reason to set a length for Integer datatypes

http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html

 

Straight from the MySQL manual

and which one suites it best? INT vs TinyINT, VARCHAR vs CHAR, etc etc,

It's pretty straight forward....if you think you're gonna need numbers up in the billions then use a BIGINT

IF you think you won't need numbers past 127 then stick with tinyint.  It's all about what you need...not what's the rule.

the 11 stands for the max number of digits....but either way....if you have an 11 digit length and you enter 99999999999 ... it will not work

 

you may get an out of range error...and you will ONLY get the maximum value for that numeric type for your value.....in this case 2147483647

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.