Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The Operation method of realizing replace into in MySQL

Shulou Source: shulou.com Published: 2022-06-03 07:21:15 10月21日 Update

This article mainly introduces the operation method of realizing replace into in MySQL. The content of the article is carefully selected and edited by the author. It has certain pertinence and is of great significance to everyone's reference. Let's learn about the operation method of realizing replace into in MySQL with the author.

Let's take a look at the following implementation process.

Prepare the data sheet

CREATE TABLE `demo` (`id` int (11) unsigned NOT NULL AUTO_INCREMENT, `a` tinyint (1) unsigned NOT NULL DEFAULT '0commands, `b` tinyint (1) unsigned NOT NULL DEFAULT' 0levels, `c` tinyint (1) unsigned NOT NULL DEFAULT '0levels, `d` tinyint (1) unsigned NOT NULL DEFAULT' 0levels, `e`tinyint (1) unsigned NOT NULL DEFAULT '0cycles, `f`tinyint (1) unsigned NOT NULL DEFAULT' 0structures, PRIMARY KEY (`id`), UNIQUE KEY `unq_a_b_ c` (`a`, `b`) `c`) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1

Note: there are two indexes in the table, with id as the primary key index and aQuery bPermec as the federated unique index.

2. Write the initial data insert into test.demo (a recital b recorder c recorder d recorder f) values (1 meme 2 recitation 3 recital 1 Jing 1)

At this point, there is unique index data composed of abc hashes: 1, 1, 2, 3.

3. To further implement replace into into demo (aPeragrum brecrium crecincdreeDifferent) values (1Mage2pence3 reparent2); because there already exist unique index data composed of three columns of abc: 1meme1, and this time it is written into demo (aQuery brecriedrecorder f) values, which will cause a unique index conflict. Therefore, the original record is deleted and a new record is added. When the replace into field has a primary key field, it will be updated that the replace into field of this record has no primark key field, and if there is a unique index conflict, the original record will be deleted, and a new record will often encounter this situation when inserting data into the table: 1. First of all, judge whether the data exists or not. If it does not exist, insert

3. If present, update

After reading the above about the operation of replace into in MySQL, many readers must have some understanding. If you need to get more industry knowledge and information, you can continue to follow our industry information column.

Tags: Index data field method real author industry conflict update information content situation meaning datasheet article time more friends column knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Information Huawei Linux MariaDB