Home > database >  This data table structure cannot batch field value add 1 ~ ~ to help you
This data table structure cannot batch field value add 1 ~ ~ to help you

Time:09-29

The data table structure is as follows:
 
DROP TABLE IF the EXISTS ` wowowo `;
The CREATE TABLE ` wowowo ` (
` guid ` bigint (10) NOT NULL,
PRIMARY KEY (` guid `)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


The data content:
 
INSERT INTO ` wowowo ` (` guid `) VALUES (' 1 ');
INSERT INTO ` wowowo ` (` guid `) VALUES (' 2 ');
INSERT INTO ` wowowo ` (` guid `) VALUES (' 3 ');
INSERT INTO ` wowowo ` (` guid `) VALUES (' 4 ');
INSERT INTO ` wowowo ` (` guid `) VALUES (' 5 ');


I want to batch update table guid value + 1
The UPDATE ` wowowo ` SET ` guid `=guid + 1;

Error: [Err] 1062 - Duplicate entry '2' for key 'PRIMARY'

Excuse me should how to batch the guid value + 1

CodePudding user response:

 
DROP TABLE IF the EXISTS ` wowowo `;
The CREATE TABLE ` wowowo ` (
` guid ` bigint (10) NOT NULL,
PRIMARY KEY (` guid `)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO ` wowowo ` (` guid `) VALUES (' 1 ');
INSERT INTO ` wowowo ` (` guid `) VALUES (' 2 ');
INSERT INTO ` wowowo ` (` guid `) VALUES (' 3 ');
INSERT INTO ` wowowo ` (` guid `) VALUES (' 4 ');
INSERT INTO ` wowowo ` (` guid `) VALUES (' 5 ');

The ALTER TABLE ` wowowo ` drop PRIMARY KEY.

The UPDATE ` wowowo ` SET ` guid `=` guid ` + 1;

The ALTER TABLE ` wowowo ` ADD PRIMARY KEY (` guid `);

SELECT * from ` wowowo `;

CodePudding user response:

Because the guid is the primary key, so can't have duplicate data

CodePudding user response:

For duplicate data,

CodePudding user response:


 UPDATE ` wowowo ` SET ` guid `=guid + 1 order by guid desc; 

CodePudding user response:

Cow upstairs!!!!!!!!!!
  • Related