[vox-tech] Altering Columns in MySQL on RedHat
Tim Riley
vox-tech@lists.lugod.org
01 Dec 2003 20:51:42 -0800
On Mon, 2003-12-01 at 20:31, Marc Elliot Hall wrote:
> I've got a RedHat 8 box running MySQL 3.23.55. One of my tables has a
> field with 'varchar(250)' as the data type.
>
> mysql> desc foo;
> +-------------+--------------+------+-----+---------+----------------+
> | Field | Type | Null | Key | Default | Extra |
> +-------------+--------------+------+-----+---------+----------------+
> | id | int(11) | | UNI | NULL | auto_increment |
> | sku | varchar(10) | | PRI | | |
> | bar | varchar(250) | | MUL | | |
> | name | text | YES | | NULL | |
> | etc... | int(11) | YES | | NULL | |
>
>
> Unfortunately, 250 characters is insufficient for the data I want to put
> into this field. So, I want to change it to 'blob' or 'text'. However,
> when I use:
>
> mysql> alter table foo modify bar text not null;
>
> I receive back the error:
>
> ERROR 1170: BLOB column 'bar' used in key specification without a key length
Try:
mysql> alter table foo modify bar text( 255 ) not null;
>
> I've tried adding a new column:
>
> mysql> alter table foo add barnew text not null;
> Query OK, 19543 rows affected (3.84 sec)
> Records: 19543 Duplicates: 0 Warnings: 0
>
> and the new column shows up:
>
> | barnew | text | | | | |
> +-------------+--------------+------+-----+---------+----------------+
>
> However, I have thus far been unable to get the values out of 'bar' and
> into 'barnew'; I'm pro'ly just being boneheaded about this and missing
> something obvious. :^)
mysql> update foo set newbar = bar;
>
> My question is this: how do I change the data type of a column that's
> part of the key? Google and http://www.mysql.com/doc/ have been (so far)
> not very helpful. Any advice is appreciated!
>
> _______________________________________________
> vox-tech mailing list
> vox-tech@lists.lugod.org
> http://lists.lugod.org/mailman/listinfo/vox-tech