在 sql 中存储针对用户的兴趣列表

Store list of interests against user in sql

我有一个用户模式,我需要存储 'interests' 列表,我来自文档数据库存储背景,我不确定在 SQL,我曾想过序列化列中的数据,但这对于搜索来说效率很低。我是否需要 'interests' table 并在其中使用外键?我不确定 SQL 中的正确实施。 谢谢

您想要一个 Interests table、一个 Users table 和一个 UserInterests table。它们应该相关:

create table Users (
    UserId serial primary key,
    . . .
);

create table Interests (
    InterestId serial primary key, 
    . . .
);

create table userInterests (
    userInterestsId serial primary key,
    UserId int references Users(UserId),
    InterestId int references Interests(InterestId),
    . . .
);