Gossamer Forum
Home : Products : Gossamer Links : Discussions :

changing Column Type

Quote Reply
changing Column Type
Howdie,

I have a colum that is set to LONGTEXT and I would like to change it to CHAR or VARCHAR (255 characters). I'd like to limit the input of text of this field to 255. Will I drop data by doing this? Will the DB drop my data completely if it is over 255? Or will it drop it regardless? Is this safe to do?

Thanks!

Last edited by:

Evoir: Jun 13, 2007, 9:14 PM
Quote Reply
Re: [Evoir] changing Column Type In reply to
I am not sure, however if I were you, I would just do a test and see what happens.

P.S.. Before doing this test, it would be very wise to make sure you have proper backup.

Hope this helps.

Vishal
-------------------------------------------------------
Quote Reply
Re: [SWDevil.Com] changing Column Type In reply to
SWDevil.Com wrote:
I am not sure, however if I were you, I would just do a test and see what happens.

P.S.. Before doing this test, it would be very wise to make sure you have proper backup.

Hope this helps.
Indeed =)

From SSH, this is the best way to backup:

Code:
mysqldump -add-drop-table -uUSERNAME -pPASSWORD DATABASE_NAME > backup.sql

Then, make sure that file was made ok.

To restore it (if you find it didn't work as you wanted), you just use:

Code:
mysql -uUSERNAME -pPASSWORD DATABASE_NAME < backup.sql

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Evoir] changing Column Type In reply to
The answer is fairly simple, without the need for backups and tests Wink

If you have a longtext column and then change it to varchar(255), yes, you will lose the data. However MySQL will first report an error saying that your data is too long when you try to change the column type.