G
Gman
Hi NG,
I have an Access DB with a VB front end connecting through ADO. I have a
table containing settings with around 30 fields. By way of example
tblSETTINGS
UserID
FormAWidth
FormAHeight
FormAColor
FormBWidth
FormBHeight
FormBColor
PathA
PathB
etc.
This works great - as discussed in a post a while back - since I can get
all the settings for a user in one recordset row in one fell swoop.
The (big) limitation of this though is that if I want to add a new
setting for a new version of the application, let's say FormCWidth, I
need to modify the table design. Since I have multiple instances of this
database it means I need to modify all the instances. This is a real
pain as you can imagine - I would rather just deploy a new executable.
Therefore I think a better solution would be to have four tables
tblSETTINGSNUMERIC
tblSETTINGSTEXT
tblSETTINGSDATES
tblSETTINGSBOOLEANS
e.g.
tblSETTINGSNUMERIC
UserID (numeric)
SettingName (text)
SettingValue (numeric, date, boolean, text depending on table)
This way I can add (and indeed remove) settings as I require without
having to modify the schema.
So far so good.
This strikes me as denormalized since I will have multiple occurrences
of the SettingName in each table. Therefore it would seem to be better
design to have the settings tables designed thus:
UserID (numeric) } PK
SettingTypeID (numeric) } PK
SettingValue (numeric, date, boolean, text depending on table)
with a fifth table:
tblSettingTypes
SettingTypeID }PK
SettingTypeName
But this makes constructing the INSERT SQL a little trickier... but doable.
INSERT INTO SettingsStrings
(UserID,SettingTypeID, SettingValue)
SELECT 1 as myUserID , PKID , 'I am a string too' as myValue
FROM SettingTypes
WHERE SettingName = 'SettingTwo'
But it means I have to insert each Setting record individually. Not
great... but I can live with it.
My questions are as follows:
(1) This must be a common requirement (right?) is there a common practise?
(2) Should I really be bothered about normalization for a table like
this and therefore I could just use 4 tables?
(3) Has anyone got any better ideas?
(4) Would anyone recommend the approach of having the application check
the structure of the Settings table and adding the new field if missing?
Sounds nasty to me.
Many thanks in advance,
Gman
I have an Access DB with a VB front end connecting through ADO. I have a
table containing settings with around 30 fields. By way of example
tblSETTINGS
UserID
FormAWidth
FormAHeight
FormAColor
FormBWidth
FormBHeight
FormBColor
PathA
PathB
etc.
This works great - as discussed in a post a while back - since I can get
all the settings for a user in one recordset row in one fell swoop.
The (big) limitation of this though is that if I want to add a new
setting for a new version of the application, let's say FormCWidth, I
need to modify the table design. Since I have multiple instances of this
database it means I need to modify all the instances. This is a real
pain as you can imagine - I would rather just deploy a new executable.
Therefore I think a better solution would be to have four tables
tblSETTINGSNUMERIC
tblSETTINGSTEXT
tblSETTINGSDATES
tblSETTINGSBOOLEANS
e.g.
tblSETTINGSNUMERIC
UserID (numeric)
SettingName (text)
SettingValue (numeric, date, boolean, text depending on table)
This way I can add (and indeed remove) settings as I require without
having to modify the schema.
So far so good.
This strikes me as denormalized since I will have multiple occurrences
of the SettingName in each table. Therefore it would seem to be better
design to have the settings tables designed thus:
UserID (numeric) } PK
SettingTypeID (numeric) } PK
SettingValue (numeric, date, boolean, text depending on table)
with a fifth table:
tblSettingTypes
SettingTypeID }PK
SettingTypeName
But this makes constructing the INSERT SQL a little trickier... but doable.
INSERT INTO SettingsStrings
(UserID,SettingTypeID, SettingValue)
SELECT 1 as myUserID , PKID , 'I am a string too' as myValue
FROM SettingTypes
WHERE SettingName = 'SettingTwo'
But it means I have to insert each Setting record individually. Not
great... but I can live with it.
My questions are as follows:
(1) This must be a common requirement (right?) is there a common practise?
(2) Should I really be bothered about normalization for a table like
this and therefore I could just use 4 tables?
(3) Has anyone got any better ideas?
(4) Would anyone recommend the approach of having the application check
the structure of the Settings table and adding the new field if missing?
Sounds nasty to me.
Many thanks in advance,
Gman