warhead2020 Posted December 18, 2009 Share Posted December 18, 2009 Hi, Im quite new to mysql/DB. I have simple question. Lets say I want to create one column 'Number'. Yeah i know, the data type should be int/double. But if i declare it as 'Varchar(100)', is there any effect in term of performance/speed etc etc etc? I know to some ppl it is simple but for me its quite important. Thanx in advance. Quote Link to comment https://forums.phpfreaks.com/topic/185600-mysql-data-type-and-size/ Share on other sites More sharing options...
cags Posted December 18, 2009 Share Posted December 18, 2009 What reason do you have for wishing to store a number as a varchar? Quote Link to comment https://forums.phpfreaks.com/topic/185600-mysql-data-type-and-size/#findComment-979880 Share on other sites More sharing options...
warhead2020 Posted December 18, 2009 Author Share Posted December 18, 2009 What reason do you have for wishing to store a number as a varchar? Logically there is no problem to insert number into varchar right? But i need to know what happen if we insert number into varchar with 100 or more in size. Quote Link to comment https://forums.phpfreaks.com/topic/185600-mysql-data-type-and-size/#findComment-979891 Share on other sites More sharing options...
PFMaBiSmAd Posted December 18, 2009 Share Posted December 18, 2009 If you are using a string in an arithmetic operation, this is converted to a floating-point number. If you use a string data type to hold numbers and then reference the value as a number it is converted to floating-point or you must cast it back to a number so that comparisons/sorting work, thereby taking up additional processing time on each reference. Edit: Strings are sorted and compared character by character, left-to-right, which means that for example, the string '10' is less than the string '2' Quote Link to comment https://forums.phpfreaks.com/topic/185600-mysql-data-type-and-size/#findComment-979894 Share on other sites More sharing options...
fenway Posted December 18, 2009 Share Posted December 18, 2009 Logically there is no problem to insert number into varchar right? Actually, it's quite illogical to store a number as anything but a number. Quote Link to comment https://forums.phpfreaks.com/topic/185600-mysql-data-type-and-size/#findComment-979903 Share on other sites More sharing options...
warhead2020 Posted December 18, 2009 Author Share Posted December 18, 2009 Logically there is no problem to insert number into varchar right? Actually, it's quite illogical to store a number as anything but a number. But still u can insert number into varchar column right? I jus want to know is there any effect to performance/size etc? Maybe your DB size will be bigger or anything?? just curious... Quote Link to comment https://forums.phpfreaks.com/topic/185600-mysql-data-type-and-size/#findComment-979915 Share on other sites More sharing options...
fenway Posted December 18, 2009 Share Posted December 18, 2009 Yes, storage is worse. Yes, comparing this value to another number is slower. Yes, MySQL will let you do it. But don't. Quote Link to comment https://forums.phpfreaks.com/topic/185600-mysql-data-type-and-size/#findComment-979959 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.