问题:如下图在Sqlite数据库中存在一张Student表,现需要向表中插入数据,如果不存在同名记录则插入,否则不进行插入操作。

  解答:利用not exists语句,如下:

insert into [Student]([Name], [Age]) select '周俊豪', 21 
where not exists (select * from [Student] where [Name]='周俊豪')  

  执行该语句,第一遍执行之后会将 周俊豪 这条数据插入,再次执行则不再进行插入操作了。

 

  文章同步更新:http://www.motyer.cn/Files/BlogDetails/sqlite-insert-into-where-not-exists.html

  桌面软件定制、中小型网站建设、移动APP开发请添加QQ/微信:773347113。

版权声明:本文为liujian619原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/liujian619/p/sqlite-insert-into-where-not-exists.html