It seems INSERT
and UPDATE
do the same things to me.
Is there any occasions where I should use INSERT
instead of UPDATE
and vice versa?
Insertion is inserting a new key and update is updating the value of an existing key. If that is the case (a very common case) , update would be faster than insertion because update involves an indexed lookup and changing an existing value without touching the index.
Insert is more faster than update because in insert there's no checking of data.
Insert command is used to insert a new row to an existing table, Update is a SQL command that is used to update existing records in a database, while alter is a SQL command that is used to modify, delete or add a column to an existing table in a database.
When you insert a new row into a table if the row causes a duplicate in UNIQUE index or PRIMARY KEY , MySQL will issue an error. However, if you specify the ON DUPLICATE KEY UPDATE option in the INSERT statement, MySQL will update the existing row with the new values instead.
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.
Use INSERT
to insert a new record.
Use UPDATE
to update an existing record.
You cannot UPDATE a row that's not in a table.
You cannot INSERT a row that's already in a table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With