-- add the column, with no unique constraint
ALTER TABLE b_iblock_element
ADD `XML_ID_UNIQUE` INT NOT NULL AFTER `XML_ID`;
-- assign the values in the column some unique values
UPDATE b_iblock_element
SET XML_ID_UNIQUE = <something unique>;
-- add in the unique constraint
ALTER TABLE b_iblock_element ADD CONSTRAINT unq_XML_ID_UNIQUE UNIQUE (b_iblock_element);
``` `<something unique>` 可以指定为:
1条答案
按热度按时间snz8szmq1#
如果表中有数据,则需要分三步进行:
UPDATE b_iblock_element CROSS JOIN
(SELECT @rn := 0) params
SET XML_ID_UNIQUE = (@rn := @rn + 1);