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:
- ALTER the table to add new INT UNSIGNED column
- Copy data from the TEXT column to INT column using CAST()
- 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
精彩评论