Heim > Fragen und Antworten > Hauptteil
阿神2017-04-17 16:01:20
1、获取当前最大id,max(id)+1
INSERT INTO myTable (name,sort)
SELECT 'Ali' as name,max(id)+1 as sort FROM myTable;
2、触发器
CREATE TRIGGER t_afterinsert_on_myTable
AFTER INSERT ON myTable
FOR EACH ROW
BEGIN
update myTable set sort=id where id=new.id;
END;
然后插入的时候只要插入name值,INSERT INTO myTable (name) VALUES ('Ali');
当然是第一种比较简单。。。