mysql删除自增长主键

mysql删除自增长主键


    /**
     * 删除主键自动增长
     *
     * @param jdbcTemplate jdbcTemplate
     * @param backupMode   备份方式
     * @param tableName    表面
     */
    private void deleteAutoIncrement(JdbcTemplate jdbcTemplate, String backupMode, String tableName) {
        //删除自动增长
        String descSql = String.format("DESC %s", tableName + "_" + backupMode);
        List<Map<String, Object>> maps1 = jdbcTemplate.queryForList(descSql);
        for (Map<String, Object> stringObjectMap : maps1) {
            Object key = stringObjectMap.get("Key");
            if ("PRI".equals(key)) {
                Object extra = stringObjectMap.get("Extra");
                if (!StringUtils.isEmpty(extra)) {
                    Object type = stringObjectMap.get("Type");
                    Object field = stringObjectMap.get("Field");
                    String dropAutoIncrement = String.format("ALTER TABLE %s CHANGE %s  %s %s UNSIGNED NOT NULL", tableName + "_" + backupMode,
                            field, field, type);
                    jdbcTemplate.execute(dropAutoIncrement);
                    break;
                }
            }
        }
    }

你可能感兴趣的:(mysql)