Efficient way to ensure unique rows in SQLite3

后端 未结 5 1493
情话喂你
情话喂你 2021-01-31 04:20

I am using SQLite3 in one of my projects and I need to ensure that the rows that are inserted into a table are unique with regard to a combination of some of their columns. In m

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-31 04:34

    Case When Exists((Select ID From Table Where Fld0 = value0 and Fld2 = value1 and Fld3 = value 2)) Then
        --Insert Statement
    End
    

    I'm not 100% that the insert works like that in SQLite, but I think it should. This with proper indexing on the Where fields should be rather quick. However this is two transactions which is something to consider.

提交回复
热议问题