Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Just after opinions here. I have an SQLite table that holds e-mail account details, one row of which will be the default account. Which would be the better design to mark the default row?

a) Have a separate table (max 1 row) with one field, which is the rowid of the default row in the Accounts table
or
b) Have an 'IsDefault' column (probably indexed) in the Accounts table, with a trigger so that if it is set, it clears the flag in the existing default row.

Does is also depend on the expected size of the Accounts table (will be small)?

Cheers,

Mick

What I have tried:

Currently using the separate table method - just wondering if this is best practice or not?
Posted
Updated 11-Mar-16 2:53am

1 solution

In my opinion the separate table is the "more beautiful" solution. While triggers would allow you to ensure that there's only ever one record marked as default, with the separate table solution it can't happen in the first place and there's no need to update the former default record when declaring another one as the new default. I'm using it myself: I have a table "DefaultValue" which holds one record with foreign keys to several other tables for which defaults have to be defined.

PS: Also the query for the default record doesn't require a table scan (or index) that way which might matter if you need to define a default record on a table that holds a few more records than in your current case.
 
Share this answer
 
v2
Comments
Midi_Mick 11-Mar-16 8:59am    
Ta mate - that's exactly what I have now - was just wondering if I was doing it right (I'm definitely NOT an SQL guru). I'll get in and mark this as solution once I leave a bit of time for other possible opinions.
Sascha Lefèvre 11-Mar-16 9:05am    
Sure! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900