-1

在这个表中

mysql> select * from classics;
+--------------------------+------------------------------+-----------------+------+-------+---------------+
| author                   | title                        | category        | year | pages | isbn          |
+--------------------------+------------------------------+-----------------+------+-------+---------------+
| Mark Twain (S.L.Clemens) | the adventures of tom sawyer | Classic Fiction | 1876 | 65535 |               |
| Charles Dickens          | A Christmas Carol            | Classic Fiction | 1849 |    50 | 23423664      |
| NULL                     | NULL                         | NULL            | NULL |  NULL | 23242362346   |
+--------------------------+------------------------------+-----------------+------+-------+---------------+

如何删除最后一行并设置第一行的isbn编号?我正在尝试这样的事情:

alter table classics drop ?? where author=NULL;
insert into classics(isbn) values('234525246') where title like "%adventures%";

如何正确执行此操作?

4

1 回答 1

1

为此,您需要 2 个语句。要删除行使用delete

delete from classics 
where author IS NULL;

要更新现有行中的值,请使用update

update classics 
set isbn = '234525246'
where title like '%adventures%';

alter用于更改表的结构而不是其内容。
insert用于向表中插入新数据,而不是修改现有数据。

于 2013-04-07T10:32:42.610 回答