main
黄海 9 months ago
parent 9387daf1a9
commit 4f6f474952

@ -70,18 +70,8 @@ public class addDataEaseExcelPrimary {
// 添加主键列和时间戳列,并设置为主键
public static void addPrimaryKeyAndTimestamp(String tableName) {
// 添加 id 列和 update_ts 列
String alterTableSql = "ALTER TABLE `" + tableName + "` ADD COLUMN `id` CHAR(36) NULL, ADD COLUMN `update_ts` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP";
// 添加 id 列
String alterTableSql = "ALTER TABLE `" + tableName + "` ADD COLUMN `id` int(11) primary key auto_increment first";
Db.use("dataease").update(alterTableSql);
// 生成 UUID 并更新 id 列和 update_ts 列
String updateSql = "UPDATE `" + tableName + "` SET `id` = UUID(), `update_ts` = CURRENT_TIMESTAMP";
Db.use("dataease").update(updateSql);
//设置主键
String sql="ALTER TABLE `" + tableName +"` MODIFY COLUMN `id` char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,ADD PRIMARY KEY (`ID`)";
System.out.println(sql);
Db.use("dataease").update(sql);
}
}

Loading…
Cancel
Save