我如何 update/rename table 行 MySQL

How do I update/rename a table row in MySQL

我有一个 table 看起来像这样:

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

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

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

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

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

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

添加新行应该只是 SQL 中的一般 INSERT INTO 语句: INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...); 查看此 link for INSERT statements and here 以了解 SQL 中的删除语句。希望对你有帮助。