sql语句INSERT INTO `custom_table_table_rltn`(`id`, `create_time`, `update_time`, `create_id`, `update_id`, `app_id`, `rltn_name`, `rltn_code`, `rltn_type`, `rltn_table_app_domain`, `primary_table_id`, `primary_table_name`, `primary_field_id`, `primary_field_name`, `foreign_table_id`, `foreign_table_name`, `foreign_field_id`, `foreign_field_name`, `rltn_table_name`, `cascade_delete_flag`, `foreign_data_delete_flag`, `query_primary_data`, `source`, `primary_table_app_domain`, `foreign_table_app_domain`, `level_type`) VALUES (2958011000000455, '2023-07-07 16:02:15', '2023-07-07 16:02:15', 1911, 1911, 2958, 'cus_vote_cus_vote_option', 'cus_vote_cus_vote_option', '2', '', 2958011000008623, 'cus_vote', 2958011000108086, 'code', 2958011000008624, 'cus_vote_option', 2958011000108088, 'vote_code', NULL, 1, 1, 0, 1, 'xndx', 'xndx', 0)中的2958011000000455替换成查询出该表的id最大值加1
时间: 2023-10-22 14:07:55 浏览: 59
你可以使用以下 SQL 语句将指定的值替换为查询出该表的 id 最大值加 1:
```sql
INSERT INTO `custom_table_table_rltn`(`id`, `create_time`, `update_time`, `create_id`, `update_id`, `app_id`, `rltn_name`, `rltn_code`, `rltn_type`, `rltn_table_app_domain`, `primary_table_id`, `primary_table_name`, `primary_field_id`, `primary_field_name`, `foreign_table_id`, `foreign_table_name`, `foreign_field_id`, `foreign_field_name`, `rltn_table_name`, `cascade_delete_flag`, `foreign_data_delete_flag`, `query_primary_data`, `source`, `primary_table_app_domain`, `foreign_table_app_domain`, `level_type`)
VALUES ((SELECT MAX(id) + 1 FROM custom_table_table_rltn), '2023-07-07 16:02:15', '2023-07-07 16:02:15', 1911, 1911, 2958, 'cus_vote_cus_vote_option', 'cus_vote_cus_vote_option', '2', '', 2958011000008623, 'cus_vote', 2958011000108086, 'code', 2958011000008624, 'cus_vote_option', 2958011000108088, 'vote_code', NULL, 1, 1, 0, 1, 'xndx', 'xndx', 0);
```
在上述代码中,使用子查询 `(SELECT MAX(id) + 1 FROM custom_table_table_rltn)` 来获取表中最大的 id 值,并将其加 1。然后将这个新的 id 值用于插入操作。
确保将 `custom_table_table_rltn` 替换为目标表的名称,并根据实际情况调整其他列的数值。这样,每次插入数据时,都会使用表中最大的 id 值加 1 作为新的 id 值。
相关推荐
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)