I’m making a dictionary database in SQLite and need some tips. My SQL is a bit rusty 😉 Would you consider this good SQL? It’s done with Java JDBC.
This is for creating the tables.
CREATE TABLE word (
id INTEGER,
entry STRING,
pos STRING
);
CREATE TABLE translation (
word_id INTEGER REFERENCES word(id),
entry STRING
);
And when filling with data i give each word a number (id) and that words translations get the same number as word_id. What would be the best way of pulling out translations for a specific word?
word_id INTEGER REFERENCES word(id)doesn’t actually create a foreign key on MySQL. Even if you’re using InnoDB, it requires an explicitFOREIGN KEYdeclaration.Also, I’d probably use an autonumber for IDs for both tables, plus mark then as primary keys.
So, taking both of those into account, plus mpacona’s note about multiple translations needing a many-to-many relationship:
Edit: I wasn’t sure what pos was, so I limited it to 50 characters. You may also need to adjust TEXT to one of its larger variants if you need more than 32k characters.
Updated lang to 5 characters to support
en-usstyle syntax.