本文介绍了sqlite插入...不存在并获取ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
即使我使用INSERT INTO ...,在不存在的地方,也有可能获取ID吗?如何对其进行修改,以便将插入记录的ID或已经存在的记录的ID带给我?如果可能的话!
is it possible to get the id even if I use INSERT INTO ... WHERE NOT EXISTS? how to modify it so it will bring me the id of the inserted record or the id of the already existed record? if possible at all!
INSERT INTO Timeline (name, ts) SELECT @name, @ts WHERE NOT EXISTS (SELECT 1 FROM Timeline WHERE name=@name AND ts = @ts);我有一个名为" id "的列,该列具有自动递增整数我如何获得ID的值?
i have a column called "id" with auto increment integer how I can get the value of the ID?
欢呼
推荐答案您保证(name,ts)是唯一的,因此应该可以解决问题.
You are guaranteeing that (name,ts) is unique, so this should do the trick.
INSERT INTO Timeline (name, ts) SELECT @name, @ts WHERE NOT EXISTS (SELECT 1 FROM Timeline WHERE name=@name AND ts = @ts); SELECT id, name, ts from TimeLine WHERE name=@name AND ts = @ts更多推荐
sqlite插入...不存在并获取ID?
发布评论