I am making a SQLite database with Java interface where the user can input information for different dates. Basically its like a diary. But I am having trouble constructing a table for the database.
I have fields called year (eg 2011), month (from 1 to 12), dayofmonth (from 1 to 31) and other fields relating to user input. But none of these are any good for a primary field. I thought of concatenating yearmonthdayofmonth so January 11 2011 is 20111101 (making sure values less than 10 have a zero in front, so it isnt the same as November 1st 2011, for example). But this seems clumsy, even if it returns unique numbers.
Is there a beter way you can recommend?
I am making a SQLite database with Java interface where the user can input
Share
Consider using a simple auto-incrementing integer as the primary key. Then you can enforce uniqueness with a unique index, like;
This keeps the primary key small, avoids a computed or composite key, but still ensures correctness.