views:

33

answers:

1

I am using MYSQL.

I have a varchar field which i incorrectly used for a price. Now the ordering of this table will not work correctly putting anything over 1000 to the bottom of the list.

I need to convert this price field in an existing POPULATED database from varchar to decimal i guess?

Any help would be appreciated.

A: 

Simply use the ALTER TABLE statement.

If for example the table is called 'products' and the field is called 'product_price' you could simply use:

ALTER TABLE products MODIFY COLUMN product_price DOUBLE;

NB: As with anything, I'd be very tempted to make a backup of the data (via mysqldump) prior to performing this operation - it'll take seconds and it's always better to be safe rather than sorry. :-)

middaparka
illgive it a whirl
Andy
whats double in MySQL?
Andy
It's a high precision numeric type - see http://dev.mysql.com/doc/refman/5.1/en/numeric-types.html It's most likely overkill in this instance but ideal if you're storing pricing data pre-tax at 'n' decimal places, etc.
middaparka