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
What are differences between INSERT and UPDATE in MySQL?
提问by shin
It seems INSERT
and UPDATE
do the same things to me.
它似乎INSERT
和UPDATE
我做同样的事情。
Is there any occasions where I should use INSERT
instead of UPDATE
and vice versa?
有什么场合我应该使用INSERT
而不是,UPDATE
反之亦然?
回答by Daniel Vassallo
In CRUD operations, the INSERT
is the 'C' and the UPDATE
is the 'U'. They are two of the four basic functions of persistent storage. The other two are SELECT
and DELETE
. Without at least these four operations, a typical database system cannot be considered complete.
在CRUD 操作中,the INSERT
is the 'C' and the UPDATE
is the 'U'. 它们是持久存储的四个基本功能中的两个。另外两个是SELECT
和DELETE
。至少没有这四个操作,一个典型的数据库系统就不能被认为是完整的。
Use INSERT
to insert a new record.
使用INSERT
插入一个新的记录。
Use UPDATE
to 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 UPDATE
statement can use a WHERE
clause but INSERT
cannot.
一个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 可用于更新非空白行。