简体   繁体   中英

Tying table records together in SQLite3

I am currently working on a database structure in SQLite Studio (not sure whether that's in itself important, but might as well mention), and error messages are making me wonder whether I'm just going at it the wrong way or there's some subtlety I'm missing.

Assume two tables, people-basics (person-ID, person-NAME, person-GENDER) and people-stats (person-ID, person-NAME, person-SIZE). What I'm looking into achieving is "Every record in people-basics corresponds to a single record in people-stats.", ideally with the added property that person-ID and person-NAME in people-stats reflect the associated person-ID and person-NAME in people-basics.

I've been assuming up to now that one would achieve this with Foreign Keys, but I've also been unable to get this to work.

When I add a person in people-basics, it works fine, but then when I go over to people-stats no corresponding record exists and if I try to create one and fill the Foreign Key column with corresponding data, I get this message: "Cannot edit this cell. Details: Error while executing SQL query on database 'People': no such column: people-basics.person" (I think the message is truncated).

The DDL I currently have for my tables (auto-generated by SQLite Studio based on my GUI operations):

CREATE TABLE [people-basics] (
    [person-ID]           INTEGER PRIMARY KEY AUTOINCREMENT
                                UNIQUE
                                NOT NULL,
    [person-NAME]         TEXT    UNIQUE
                                NOT NULL,
    [person-GENDER]     TEXT
);

CREATE TABLE [people-stats] (
    [person-NAME]       TEXT    REFERENCES [people-basics] ([person-NAME]),
    [person-SIZE]     NUMERIC
);

(I've removed the person-ID column from people-stats for now as it seemed like I should only have one foreign key at a time, not sure whether that's true.)

Alright, that was a little silly.

The entire problem was solved by removing hyphens from table names and column names. (So: charBasics instead of char-basics, etc.)

Ah well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM