sponsors:

Reply to comment


MYSQL fix duplicates saving duplicated data with new id

DROP PROCEDURE `max_wid`;
DELIMITER ;;
CREATE PROCEDURE `max_wid` (OUT `y` int)
SQL SECURITY INVOKER
BEGIN
SELECT MAX(wid) into y from works;
END;;
DELIMITER ;
DELIMITER ;;
CREATE PROCEDURE `first_dup` (OUT `t` int)
SQL SECURITY INVOKER
BEGIN
SELECT wid into t FROM works GROUP BY wid HAVING ( COUNT(wid) > 1 ) LIMIT 0,1;
END;;
DELIMITER ;

The procedure itself - finding first duplicated data - and updating it to maximum possible id
After running this code till ZERO duplicates just create unique Primary key for Your table

CALL `max_wid`(@`y`);
CALL `first_dup`(@`t`);
UPDATE works set wid = ((SELECT @y) +1) WHERE wid like (SELECT @t) LIMIT 1;

Trackback URL for this post:

http://itua.name/en/trackback/944

Reply

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <img> <center> <b> <i> <u><h1><h2><h3><h4><h5><h6><strike><q><abbr><tr><td><table><br><p><div><span><embed><object>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.
Image CAPTCHA
Enter the characters shown in the image.

Syndicate content

Propeople Expert

експерименти

Rambler's Top100