FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Prefix 0 in int data type in SQL





abhinav_shah
I created a table in mysql :
Code:
create table mytab(phone int);

Now when I insert into the table,
Code:
insert into mytab values(01234);
the 0 dosen't get inserted and the value appears as 1234.
Can anyone tell me how to insert 0 in the begining ?
gamo
abhinav_shah wrote:
I created a table in mysql :
Code:
create table mytab(phone int);

Now when I insert into the table,
Code:
insert into mytab values(01234);
the 0 dosen't get inserted and the value appears as 1234.
Can anyone tell me how to insert 0 in the begining ?


You should declare that field to be varchar instead of int. In your application, if you need to get int value from that field, you can use an utility function to cast String value to Integer.
Otherwise, you can use graphics tool to manage mySql, such as: EMS mySQL, SQL Admin....

Goodluck !!!
JustaMin
You could also set a field attribute of UNSIGNED_ZEROFILL to the int field to achieve this.

However, it is essentially pointless to store zero prefixes, it's much better and allows for much more flexibilty if you just to format the data after the query...

Edit: just noticed you are storing a phone number, I would use a varchar for this as suggested above Smile
Related topics
script backup database
Fortran Tutorials(77)
MySQL DB Backup script - minor problem
writing COM components in Perl
[man]Servidor Web Personal (Tutorial)
C++ int to char and char to int
Can't create mySQL table
Need Expert help in php-mysql
Mysql 5.0 and its limitation
XML parsing
Number or date/time field for timestamp?
Date/Time Entries (PHP & MySQL)
What MySQL Data type would you use to store a Webpage
MySQL Database Backup Using PHP
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.