how to set unique constraint over multiple column when any one can be null in sqlite

前端 未结 3 1316
情歌与酒
情歌与酒 2020-12-18 11:48

How do I set unique constraint over multiple column when any one can be null in sqlite?

e.g. I have made unique(\"col1\",\"col2\",\"col3\") and tried with inse

3条回答
  •  感情败类
    2020-12-18 12:32

    In sqlite, all null are differences. I think the best way to solve this issue is to set column c not null with a special default value. Then use the default value (for example 0, '') to represent null.

    edit 1

    you can easily extend this solution to any columns

    create table test (
        a text not null default "",
        b text not null default "",
        c text not null default ""
    );
    

提交回复
热议问题