Web Hosting Talk







View Full Version : MySQL Table Change without data loss


andretenreiro
03-16-2010, 12:40 PM
I have a table with 700 entries.

I want to change its userID from INT into VARCHAR (username).


What is the best way of doing this without any data obstruction?

mattle
03-16-2010, 01:17 PM
um...alter table. Shouldn't have any problem casting the ints to varchars, provided the field size can accommodate the max number of digits in the largest value for userID

andretenreiro
03-16-2010, 01:28 PM
um...alter table. Shouldn't have any problem casting the ints to varchars, provided the field size can accommodate the max number of digits in the largest value for userID

Cool! No problem at all.

Now I'm facing another problem... How can I mass update a table?

I want to update all entries in "UserID" from 25 to "jsmith".

The only way is to create a PL/SQL code for it?

andretenreiro
03-16-2010, 01:32 PM
Cool! No problem at all.

Now I'm facing another problem... How can I mass update a table?

I want to update all entries in "UserID" from 25 to "jsmith".

The only way is to create a PL/SQL code for it?

Even easier...


UPDATE `Mission` SET `UserID` = 'jsmith' WHERE `UserID` = '25';

Sometimes things are easier than it seem (others not!) :D