开发者

Convert TEXT to INT field (submit_date)

I have a field called submit_dat开发者_开发技巧e which stores the value of a timestamp.

The field type is text - I want to convert it to INT - What is the safest way to do this?

Would converting to INT improve the performance?

Thanks


The safest way is to try ALTERing the datatype in a testing setup (i.e. not on live database). If this does not work, then you need to:

  1. ALTER the table to add new INT UNSIGNED column
  2. Copy data from the TEXT column to INT column using CAST()
  3. Drop the old column, and change the name of new one. Create indexes as needed

Yes, it should in general be faster.


Try with:

CAST(submit_date AS UNSIGNED)

or

CONVERT(submit_date, UNSIGNED)

ref: http://dev.mysql.com/doc/refman/5.1/en/cast-functions.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜