Skip to main content

Posts

Showing posts with the label REPLACE Statement

The REPLACE Statement

The MySQL-specific statement 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. REPLACE is a MySQL extension to the SQL standard. It either inserts, or  deletes and inserts. Uses the following general syntax; REPLACE INTO table_name (column_list) VALUES(value_list); In this example, we are replacing a current row of data (containing three columns) in the people database; REPLACE INTO people (id,name,age) VALUES(12,'Bruce',25); Note that unless the table has a PRIMARY KEY or a UNIQUE index, using a REPLACE statement makes  no sense. It becomes equivalent to INSERT, because there is no index to be used to determine whether a  new row duplicates another. Values for all columns are taken from the values specified in the REPLACE statement. Any missing  columns are set to their default values, just as happens for INSE