MySQL 中的 INSERT 和 UPDATE 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2002500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:55:10  来源:igfitidea点击:

What are differences between INSERT and UPDATE in MySQL?

mysqlsqlsql-updatesql-insert

提问by shin

It seems INSERTand UPDATEdo the same things to me.

它似乎INSERTUPDATE我做同样的事情。

Is there any occasions where I should use INSERTinstead of UPDATEand vice versa?

有什么场合我应该使用INSERT而不是,UPDATE反之亦然?

回答by Daniel Vassallo

In CRUD operations, the INSERTis the 'C' and the UPDATEis the 'U'. They are two of the four basic functions of persistent storage. The other two are SELECTand DELETE. Without at least these four operations, a typical database system cannot be considered complete.

CRUD 操作中,the INSERTis the 'C' and the UPDATEis the 'U'. 它们是持久存储的四个基本功能中的两个。另外两个是SELECTDELETE。至少没有这四个操作,一个典型的数据库系统就不能被认为是完整的。

Use INSERTto insert a new record.

使用INSERT插入一个新的记录。

Use UPDATEto update an existing record.

使用UPDATE更新现有的记录。

回答by slebetman

You cannot UPDATE a row that's not in a table.

您不能更新不在表中的行。

You cannot INSERT a row that's already in a table.

您不能插入已经在表中的行。

回答by Michael

Insert is for adding data to the table, update is for updating data that is already in the table.

Insert 用于向表中添加数据,update 用于更新表中已有的数据。

回答by dsa

An UPDATEstatement can use a WHEREclause but INSERTcannot.

一个UPDATE语句可以使用WHERE条款,但INSERT不能。

回答by user3162187

Insert is for putting in a fresh record to the table. while the update enables you to modify the inserted record e.g. modifying data type etc.

插入用于将新记录放入表中。而更新使您能够修改插入的记录,例如修改数据类型等。

回答by Niraj

Insert can be useful to insert new record in BLANK row. While Update can be used to update row which is NOT BLANK.

插入对于在空白行中插入新记录很有用。而 Update 可用于更新非空白行。