r/SQL • • Sep 18 '26

SQLite Join tables with WITHOUT ROWID.

CREATE TABLE IF NOT EXISTS CourseTag(
    courseId INTEGER,
    tagId INTEGER,
    
    FOREIGN KEY(courseId) REFERENCES Courses(id),
    FOREIGN KEY(tagId) REFERENCES Tags(id),
    
    PRIMARY KEY(courseId, tagId)
) STRICT WITHOUT ROWID;

as far as what I understand sqlite creates inner row_id columns to identify the record. some conditions met then my primary key also could be that unique column. but I guess in above join table configuration my composite key setup is not met that condition so I end up unnecessary column right? in join table should I use WITHOUT ROWID?

3 Upvotes

14 comments sorted by

View all comments

Show parent comment

1

u/da_chicken Sep 20 '26

I've seen systems do either approach, and I've never seen the natural primary key approach cause insert errors. It's not remotely difficult to avoid. Indeed, you have to do the same thing in either design. There's nothing about the design of a junction table that makes it more susceptible to them.

I think your experience is with a poorly implemented system. It's not something unique to not using a surrogate key.