[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Optimal mysql field type

Posted on 2004-11-10
5
Medium Priority
?
269 Views
Last Modified: 2012-06-21
Hi all,
I have a table where I need to control my id numbers by my self... no need for autoincrement.

My problem is, that some of the ID numbers HAVE TO start with a zero.. Example: 01099304
I can not use int for the fieldtype, cause that will set the value to 1099304, and varchar would make the database slow... Is there a more optimal fieldtype for this???

Best regards,
Peter
0
Comment
Question by:Crapman
  • 2
  • 2
5 Comments
 
LVL 13

Expert Comment

by:nurbek
ID: 12542125
try datatype as numeric
0
 

Author Comment

by:Crapman
ID: 12542135
Enum?
0
 
LVL 5

Accepted Solution

by:
eyeh8u earned 2000 total points
ID: 12542164
Numeric is just string storage of floating point data types, it will solve leading 0's but is probably not the best solution.

Try using the ZEROFILL Option:

http://dev.mysql.com/doc/mysql/en/Numeric_types.html

INT(8) ZEROFILL

For example, if you stored 1099304 it would be returned as 01099304 while being stored in the optimal integer data type.
0
 
LVL 13

Expert Comment

by:nurbek
ID: 12542186
sorry i was in ms sql
i dont know it numeric field datatype in mysql :(
also
Example: 01099304 (It is logically number)
but when you use it only uses 1099304 removes the 0

If you are planning to print it out as 0001099304 (if you have standart length in all)
write a function that returns as string
you can get the lenght of number and add the zeros before number and return function

0
 

Author Comment

by:Crapman
ID: 12542208
Wohoo, eyeh8u's solution worked perfectly!! :)

Thanks to both of you for your support...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Integration Management Part 2
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question