FastNetMon

Tuesday 9 August 2011

MySQL - добавление нового значения в поле типа ENUM

Допустим, ранее было вот такое поле в некой таблице:
`status` enum('new','suspended') NOT NULL,

Но в один прекрасный момент понадобилось добавлять в этот самый enum что-то еще:
ALTER TABLEsome_table MODIFY status enum('new','suspended', 'complete')

Вуаля:
`status` enum('new','suspended','complete') default NULL,

Фишка тут еще в том, что новое значение нужно добавить в конец существующего списка:
Changing the definition of an ENUM or SET column by adding new enumeration or set members to the end of the list of valid member values, as long as the storage side of the data type does not change. For example, adding a member to a SET column that has 8 members changes the required storage per value from 1 byte to 2 bytes; this will require a table copy. Adding members in the middle of the list causes renumbering of existing members, which requires a table copy.

Источник: http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

No comments :

Post a Comment

Note: only a member of this blog may post a comment.