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 dataCodePudding user response:
For duplicate data,CodePudding user response:
UPDATE ` wowowo ` SET ` guid `=guid + 1 order by guid desc;
CodePudding user response:
Cow upstairs!!!!!!!!!!