I want to create a table with two columns: user_id
, image_id
. I don't want user_id
or image_id
to be unique, but I also want to protect my table from duplicate pairs of same user_id
and image_id
. Can I do that?
我想创建一个包含两列的表:user_id,image_id。我不希望user_id或image_id是唯一的,但我也希望保护我的表免受同一user_id和image_id的重复对的影响。我能这样做吗?
1 个解决方案
#1
18
Add a separate constraint for both columns:
为两列添加单独的约束:
CREATE TABLE MyTable(
user_id INTEGER,
image_id INTEGER,
[...],
UNIQUE(user_id, image_id)
)
#1
18
Add a separate constraint for both columns:
为两列添加单独的约束:
CREATE TABLE MyTable(
user_id INTEGER,
image_id INTEGER,
[...],
UNIQUE(user_id, image_id)
)