| Author |
Topic |
|
DavidChel
Constraint Violating Yak Guru
474 Posts |
Posted - 2008-11-12 : 17:05:12
|
| Suppose I have a field and it could be used one of two ways, as a 6 digit number only field or as a 5 digit char field. How much space would each entry take up in each of those cases? I hope I worded that question intelligently. |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2008-11-12 : 17:12:30
|
| what is the data type of said column? |
 |
|
|
DavidChel
Constraint Violating Yak Guru
474 Posts |
Posted - 2008-11-12 : 17:16:00
|
| Oh, sorry. Int. |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2008-11-12 : 17:20:18
|
quote: Originally posted by DavidChel Oh, sorry. Int.
According to BOL INT columns takes up 4 bytes of storage. Although, I'm not sure how you would store character data in an INT. |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-11-12 : 17:26:53
|
quote: Originally posted by Lamprey
quote: Originally posted by DavidChel Oh, sorry. Int.
According to BOL INT columns takes up 4 bytes of storage. Although, I'm not sure how you would store character data in an INT.
You can't store it in INT. |
 |
|
|
DavidChel
Constraint Violating Yak Guru
474 Posts |
Posted - 2008-11-12 : 17:32:10
|
| And how much space would a 5 digit char field require? 5 bytes? |
 |
|
|
DavidChel
Constraint Violating Yak Guru
474 Posts |
Posted - 2008-11-13 : 10:39:24
|
| Is this a dumb question or something? |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-11-13 : 10:43:45
|
| Yes , each character takes 1 byte. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-13 : 10:44:14
|
quote: Originally posted by DavidChel Is this a dumb question or something?
i think you should declare it as varchar(6). this means it can hold a maximum of 6 characters and also makes sure it allocates the space only based on actual number of characters you store. |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2008-11-13 : 11:57:40
|
| Do you nee to support Unicode data?Do you want a variable length (varchar or nvarchar) or fixed length (char or nchar) column or do you want to hash the text to fit in an integer column or even something like a sql_variant datatype? Understanding the data types offered by SQL Server is pretty fundamental to working with SQL Sever. More fundamental is to understand relational concepts (read: An Introduction to Database Systems by C.J. Date). That is probably not the answer you are looking for, so I suggest that you look at BOL (Books Online) and explore the different data types. That will tell you how much storage space each type takes and what they can store. |
 |
|
|
DavidChel
Constraint Violating Yak Guru
474 Posts |
Posted - 2008-11-13 : 16:55:14
|
| I never know how much to say because I want to make my questions as easy to answer as possible. The current field is a varchar field so that base36 numbering can be used to maximize the number of combinations. What I was wondering was is a 5 digit varchar field larger or smaller than an INT field since we could have sufficed with the number range of the INT data type? Since an INT type is only 4 bytes and a 5 digit Varchar is 5, then they didn't use Base36 for space savings. Thanks guys. |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2008-11-13 : 17:10:11
|
| I just did a quick conversion and the largest INT (2,147,483,647) converts to ZIK0ZJ in base 36. So, it would take 6 bytes to store the same number in base 36 versus 4 bytes (assuming my conversion is correct). |
 |
|
|
|