fylix0000
asked on
Question about tinyint, smallint datatype.
Hi, I just created a table with
create table X (
var1 tinyint,
var2 smallint)
I then check the table properties with sp_help X and what I saw is the var1 column only has length of 1 and var2 has length of 2.
I know tinyint is 1 byte so it goes up to 255 and small int is 2 bytes so it goes up to 2^8 number I think. Will SQL server increase my field length automatically?
create table X (
var1 tinyint,
var2 smallint)
I then check the table properties with sp_help X and what I saw is the var1 column only has length of 1 and var2 has length of 2.
I know tinyint is 1 byte so it goes up to 255 and small int is 2 bytes so it goes up to 2^8 number I think. Will SQL server increase my field length automatically?
Actually, small int goes 2^15-1, so that's up to 32767.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
"the LENGTH you see is only the number of BYTES this column will use for storing the values, not the number of digits." so basically even though I see 1 in the field length, that does not mean i can only insert number 1-9, but rather any number within the limit.
BriCrowe, I was afraid I am retricted to the length I can insert in, in this case only number 1 to 9, I would have no problem if the small int limit at 2^15 - 1 (32,767). Though thanks for explain it in detail.
BriCrowe, I was afraid I am retricted to the length I can insert in, in this case only number 1 to 9, I would have no problem if the small int limit at 2^15 - 1 (32,767). Though thanks for explain it in detail.
Wow... so the link I provided was of no help to you, eplaining the data types?
ASKER
Sorry Leew :( , the question I put out only worth 100 points and I am more asking about the field lenght and not the data type information I saw in the database and angelIII's answer is what I was looking for. Your link is very good at explain the data type in detail but I gave BriCrow part points mainly becuase for the time he took type out in detail. I hope you do not think I did not appricate your helps.
ok... I thought you understood that 2 didn't mean two digits because you said:
> I know tinyint is 1 byte so it goes up to 255
That's why I said 32767 was the maximum...
At the same time I thought you might be confused about the value
> I know tinyint is 1 byte so it goes up to 255
That's why I said 32767 was the maximum...
At the same time I thought you might be confused about the value