sqlite插入...不存在并获取ID?

编程入门 行业动态 更新时间:2024-10-26 04:27:01
本文介绍了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?

本文发布于:2023-10-27 16:11:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533885.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不存在   sqlite   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!