If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Data type suggestion (easy one hopefully)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-01-07, 07:21
nooch32 nooch32 is offline
Registered User
 
Join Date: Aug 2007
Posts: 6
Question Data type suggestion (easy one hopefully)

I'm creating a database which will house millions of rows of data. The problem i'm having is i have a field which is to store a number of 35 characters. Obviously INT and BIG INT are too small. I am reluctant to use VARCHAR( 35) as I want to search the database via a query number BETWEEN X and Y and am concerned about speed of the query if i use a VARCHAR.

Any suggestions?


Thanks in advance
Reply With Quote
  #2 (permalink)  
Old 08-01-07, 07:37
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
I reckon decimal might be worth a look.
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 08-01-07, 07:54
nooch32 nooch32 is offline
Registered User
 
Join Date: Aug 2007
Posts: 6
The numeric values will be whole numbers only
Reply With Quote
  #4 (permalink)  
Old 08-01-07, 07:57
nooch32 nooch32 is offline
Registered User
 
Join Date: Aug 2007
Posts: 6
Actually it seems to output ok with test data
Reply With Quote
  #5 (permalink)  
Old 08-01-07, 07:57
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Would Numeric(35,0) do the trick then?
__________________
George
Twitter | Blog
Reply With Quote
  #6 (permalink)  
Old 08-01-07, 08:05
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by nooch32
I am reluctant to use VARCHAR( 35) as I want to search the database via a query number BETWEEN X and Y and am concerned about speed of the query if i use a VARCHAR.
right-justify your numbers in a CHAR(35) column with leading zeroes (or spaces if you insist)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 08-01-07, 08:07
nooch32 nooch32 is offline
Registered User
 
Join Date: Aug 2007
Posts: 6
not liking the idea of corrupting the data with leading zeros. Also, with them being numbers and i did a query to get a range of numbers, wouldn't they get converted if they were stored as CHARs? Got to remember this is a huge database i'm working on, so speed is essential.
Reply With Quote
  #8 (permalink)  
Old 08-01-07, 08:11
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
leading zeroes do not actually corrupt numbers

by suggesting that, you are actually admitting that they really are strings, not numbers

so use leading spaces

and converted to what? no, they wouldn't get converted, they'd be CHAR strings
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 08-01-07, 08:14
nooch32 nooch32 is offline
Registered User
 
Join Date: Aug 2007
Posts: 6
Although i like the idea of DECIMAL, i've just realised that there won't be any calculations as such on these numbers. Also, just found out the number needs a leading 0 (yep, phone numbers). Also PHP won't handle the number of 35 characters very well, ie we'd have to convert it over to a string. Think it might just be easier to store as VARCHAR(35) as before
Reply With Quote
  #10 (permalink)  
Old 08-01-07, 08:15
nooch32 nooch32 is offline
Registered User
 
Join Date: Aug 2007
Posts: 6
r937, think you've got it, essentially i should look at them as strings
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On