Reputation: 2609
I want add 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'
Upvotes: 2
Views: 8094
Reputation: 4366
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.
Upvotes: 5
Reputation: 4199
Concering the docu:
ALTER TABLE cxt_20110105 ADD COLUMN tbn INT(1) DEFAULT '1'
Upvotes: 6