Jump to content

Which types?


dmccabe

Recommended Posts

I am making a form for user to input new account information and am unsure which types to use for the best results.

 

For a telephone number is it best to use a VARCHAR ?

 

What about a block of text? BLOB?

 

Radio buttons which serve as YES/NO  ???

 

Any pointers would be appreciated :)

Link to comment
Share on other sites

There will be a lot of variation based on personal preference, but for the things you listed:

 

Phone: VARCHAR

Text: *TEXT (there are a couple different variations of the TEXT type)

Yes/No: INT(1) with a 0/1 stored in it

 

 

Link to comment
Share on other sites

Text: *TEXT (there are a couple different variations of the TEXT type)

 

Sorry I should be asking all the questions at once instead of just as they come.

 

but what do you mean there are a couple of variations of text ? and which one should I be using ?  is "*TEXT" an actual type?

 

**EDIT** IGNORE - I see them now TEXT/MEDIUMTEXT/LONGTEXT  I have chose long text.

Link to comment
Share on other sites

excuse my ignorance, but what is the (1) after INT and TINYINT ?

 

is it what I put in the length/value in phpmyadmin?

Yes

 

Just another thought, with the values now being an INT or TINYINT should I be passing the value of 1 or 0 instead of yes or no?

Pass 1 for yes and 0 for No.

Link to comment
Share on other sites

I should probably point out however that if you want a BIT to come out as an numeric representation you'll need to do the following:

SELECT `bitfield`+0 FROM ...

 

You need to +0 to the field that contains the bit to get the numeric representation out of it.

 

note: this is as of 5.0.3

Link to comment
Share on other sites

Use numeric for monetary amounts, e.g. NUMERIC(4,2) will allow you a value up to 9999.99 .

It ALSO has the added benefit of doing correct calculations on large numbers as opposed to double/float which suffer from 32bit rounding.

Link to comment
Share on other sites

Thanks guys!

 

 

One last question, when inputting a monetry amount would you use the type of "DECIMAL" ?

I use DOUBLE.

DOUBLE is terrible for monetary values -- floating-point error hell.

 

Check the mysql documentation for the size limitations of the different TEXT types. I have never needed anything more than TEXT. Also, regarding a yes|no option, you can always use BIT(1) ;)

In v5+, VARCHAR can be up to 65K -- much, much better than TEXT for about 15 different reasons.

 

And as for yes/no, I question your db design.

Link to comment
Share on other sites

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.