I want ad开发者_运维问答d a new field in my database, and set all rows values = '1'.
How to do it correctly?
ALTER TABLE `cxt_20110105` ADD COLUMN tbn INT(1) SET tbn = '1'
Concering the docu:
ALTER TABLE cxt_20110105 ADD COLUMN tbn INT(1) DEFAULT '1'
UPDATE TABLE cxt_20110105 SET tbn = 1;
Just be carefull that
ALTER TABLE cxt_20110105 ADD COLUMN tbn INT(1) DEFAULT '1'
will result in every row added hereafter without a value for tbn
being set to '1'
if you're just using it as initial value and dont want future rows to default to a value you can do this after:
alter table cxt_20110105 change tbn tbn int(1)
If you're using MyISAM, it is a fast operation.
精彩评论