My being fairly new to SQL, I was wondering if I could use it to solve one of the complexities in my database automatically.
That is, I’m tracking entries by day.
So, the columns we are concerned with are:
YYYYMMDDXXX
where YYYY is year, MM is month, DD is day and XXX is a unique number given to each entry on a given day. In such a way is uniqueness ensured.
My question is if I can use SQL to automatically increment XXX (from 0) if I enter two records with the same YYYY, MM and DD.
If not, I could do a query and manually check (but this would be easier).
I suppose the other option would be to use the _id column (that is _id INTEGER PRIMARY KEY AUTOINCREMENT) which is guaranteed to be unique for every row. Would that just be a better solution?
I’m use the Android SQLite implementation (with Java)
Thanks!
We really need more details to give a good answer, but it sounds like just using an auto incrementing id as the primary key is a cleaner solution. In general, storing a string combining the date with a counter appended to the end is a bad idea.