Files
universaltestsoftware_clien…/update_channel_data_structure.sql
2026-07-13 13:25:21 +08:00

19 lines
647 B
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# new_id字段
ALTER TABLE channel_data ADD COLUMN new_id INT NOT NULL FIRST;
# new_id赋值
SET @row_num = 0;
UPDATE channel_data SET new_id = (@row_num := @row_num + 1);
# new_id设为主键
ALTER TABLE channel_data DROP PRIMARY KEY, ADD PRIMARY KEY (new_id);
# new_id设置为自增
ALTER TABLE channel_data MODIFY COLUMN new_id INT NOT NULL AUTO_INCREMENT;
# data_id字段
ALTER TABLE channel_data DROP COLUMN data_id;
# new_id字段为data_id
ALTER TABLE channel_data CHANGE COLUMN new_id data_id INT NOT NULL AUTO_INCREMENT;