FRIHOSTFORUMSSEARCHFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a 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

Date/Time Entries (PHP & MySQL)
Number or date/time field for timestamp?
script backup database
MySQL DB Backup script - minor problem
Need Expert help in php-mysql

Fortran Tutorials(77)
writing COM components in Perl
[man]Servidor Web Personal (Tutorial)
C++ int to char and char to int
Can't create mySQL table

Mysql 5.0 and its limitation
XML parsing
whats wrong with this mysql query?
MySql or MsSql?
Problem with Calander.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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