我有一个看起来像这样的表:

   +-----------+---------+-----------+------+-----+---------+----------------+---------------------------------+---------+
    | Field     | Type    | Collation | Null | Key | Default | Extra          | Privileges                      | Comment |
    +-----------+---------+-----------+------+-----+---------+----------------+---------------------------------+---------+
    | id        | int(11) | NULL      | NO   | PRI | NULL    | auto_increment | select,insert,update,references |         |
    | l125      | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | l250      | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | l500      | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | l1000     | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | l2000     | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | l4000     | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | l6000     | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | l8000     | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | r125      | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | r250      | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | r500      | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | r1000     | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | r2000     | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | r4000     | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | r6000     | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | r8000     | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | accountId | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | l3000     | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    | r3000     | int(11) | NULL      | YES  |     | NULL    |                | select,insert,update,references |         |
    +-----------+---------+-----------+------+-----+---------+----------------+---------------------------------+---------+


我想修改该表,以便删除I125和I250,并添加名为l1500的新行。

最佳答案

您只需要ALTER TABLE(请注意,它们是列,而不是您要更改的行):

ALTER TABLE yourtable
    DROP COLUMN l125,
    DROP COLUMN l250,
    ADD COLUMN l1500 INT NULL DEFAULT NULL AFTER l1000


注意我假设您希望l1500列具有与其他lnnn列相同的定义。

07-28 00:16