Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between REPLACE, INSERT, UPDATE in MySql? [closed]

Can someone please explain the differences between REPLACE, INSERT and UPDATE in MySql?

like image 424
User1988 Avatar asked Dec 28 '11 06:12

User1988


People also ask

What is the difference between update and replace?

The REPLACE policy will create the record or replace it entirely if a previous version of the record already existed. This will delete potential already existing bins for this record. The UPDATE policy will create the record or update the record if it already exists.

What is the difference between INSERT and update?

The INSERT option pushes the incoming records to the destination. The UPDATE option keeps track of the records being updated in the database table.

Is INSERT same as update in MySQL?

Insert is for adding data to the table, update is for updating data that is already in the table. Show activity on this post. An UPDATE statement can use a WHERE clause but INSERT cannot.

What is replace into MySQL?

REPLACE works exactly like INSERT , except that if an old row in the table has the same value as a new row for a PRIMARY KEY or a UNIQUE index, the old row is deleted before the new row is inserted. See Section 13.2. 6, “INSERT Statement”. REPLACE is a MySQL extension to the SQL standard.


1 Answers

These are totally different statements.

  • Insert: Insert new record

  • Update: Update existing record

  • Replace: works exactly like INSERT, except that if an old row in the table has the same value as a new row for a PRIMARY KEY or a UNIQUE index, the old row is deleted before the new row is inserted

Cheers!

Prasad.

like image 103
Prasad Rajapaksha Avatar answered Nov 01 '22 22:11

Prasad Rajapaksha