码迷,mamicode.com
首页 > 数据库 > 详细

How to do IF NOT EXISTS in SQLite

时间:2016-05-10 12:24:57      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

http://stackoverflow.com/questions/531035/how-to-do-if-not-exists-in-sqlite

How about this?

INSERT OR IGNORE INTO EVENTTYPE (EventTypeName) VALUES ‘ANI Received‘

(Untested as I don‘t have SQLite... however this link is quite descriptive.)

Additionally, this should also work:

INSERT INTO EVENTTYPE (EventTypeName)
SELECT ‘ANI Received‘
WHERE NOT EXISTS (SELECT 1 FROM EVENTTYPE WHERE EventTypeName = ‘ANI Received‘);

需要注意的是,这里的Insert Into后面是没有Values;

Values是通过后面的Select来实现的

 

 

参考这个

internal static string InsertIdxFile =

@"Insert Into SensorData(ID,ProjectID,SensorIdx,IdxFile,StartTimestamp,EndTimestamp) 
SELECT ‘{0}‘,‘{1}‘,‘{2}‘,‘{3}‘,‘{4}‘,‘{5}‘
WHERE NOT EXISTS (SELECT 1 FROM SensorData WHERE ID = ‘{0}‘)";

 

How to do IF NOT EXISTS in SQLite

标签:

原文地址:http://www.cnblogs.com/chucklu/p/5477168.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!