数据库相关

2018-11-05  本文已影响0人  汝枫

mysql查询当前表最小可用id(id补缺策略)
select min(id+1) from material c where not exists (select id from material where id = c.id+1);

实例:
INSERT INTO material (id, name, content, savename)(
SELECT min(id + 1), '插入数据', '2018-11-02 17:41:34.95',
'93279e3308bdbbeed946fc965017f67a.txt'
FROM material c
WHERE
NOT EXISTS (
SELECT
id
FROM
material
WHERE
id = c.id + 1
)
);

上一篇下一篇

猜你喜欢

热点阅读