美文网首页
数据库相关

数据库相关

作者: 汝枫 | 来源:发表于2018-11-05 14:20 被阅读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
    )
    );

    相关文章

      网友评论

          本文标题:数据库相关

          本文链接:https://www.haomeiwen.com/subject/jprsxqtx.html