如何在MySQL中更新/重命名表行

问题描述 投票:0回答:2

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

   +-----------+---------+-----------+------+-----+---------+----------------+---------------------------------+---------+
    | 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 |         |
    +-----------+---------+-----------+------+-----+---------+----------------+---------------------------------+---------+

我想修改表,以便删除l125和l250,并且我想添加一个名为l1500的新行。

mysql row alter
2个回答
1
投票

你只需要ALTER TABLE(注意它们是列,而不是你正在改变的行):

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

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


0
投票

我认为该命令应该类似于: DELETE FROM table_name WHERE row_name='l250';

并且添加新行应该只是SQL中的一般INSERT INTO语句: INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...); 对于INSERT语句,请查看此link,对于SQL中的delete语句,请查看here。我希望这可以帮助你。

© www.soinside.com 2019 - 2024. All rights reserved.