我有一个看起来像这样的表:
+-----------+---------+-----------+------+-----+---------+----------------+---------------------------------+---------+
| 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的新行。
答案 0 :(得分:1)
您只需要ALTER TABLE
(请注意,它们是列,而不是您要更改的行):
ALTER TABLE yourtable
DROP COLUMN l125,
DROP COLUMN l250,
ADD COLUMN l1500 INT NULL DEFAULT NULL AFTER l1000
请注意,我假设您希望l1500
列具有与其他lnnn
列相同的定义。
答案 1 :(得分:0)