Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

sqlite insert if not exists

--- If you never want to have duplicates, you should declare this as a table constraint: ---

CREATE TABLE bookmarks(
    users_id INTEGER,
    lessoninfo_id INTEGER,
    UNIQUE(users_id, lessoninfo_id)
);

---(a primary key over both columns would have the same effect)

	It is then possible to tell the database that you want to ignore if the insert didn't work---
    
    INSERT OR IGNORE INTO bookmarks(users_id,lessoninfo_id) VALUES(123,456)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sqlite #insert #exists
ADD COMMENT
Topic
Name
8+1 =