I'm currently trying to improve the design of a legacy db and I have the following situation
Currently I have a table SalesLead in which we store the the LeadSource.
Create Table SalesLead(
....
LeadSource varchar(20)
....
)
The Lead Sources are helpfully stored in a table.
Create Table LeadSource (
LeadSourceId int, /*the PK*/
LeadSource varchar(20)
)
And so I just want to Create a foreign key from one to the other and drop the non-normalized column.
All standard stuff, I hope.
Here is my problem. I can't seem to get away from the issue that instead of writing
SELECT * FROM SalesLead Where LeadSource = 'foo'
Which is totally unambiguous I now have to write
SELECT * FROM SalesLead where FK_LeadSourceID = 1
or
SELECT * FROM SalesLead
INNER JOIN LeadSource ON SalesLead.FK_LeadSourceID = LeadSource.LeadSourceId
where LeadSource.LeadSource = "foo"
Which breaks if we ever alter the content of the LeadSource field.
In my application when ever I want to alter the value of SalesLead's LeadSource I don't want to update from 1 to 2 (for example) as I don't want to have developers having to remember these magic numbers. The ids are arbitrary and should be kept so.
How do I remove or negate the dependency on them in my app's code?
Edit Languages my solution will have to support
- .NET 2.0 + 3 (for what its worth asp.net, vb.net and c#)
- vba (access)
- db (MSSQL 2000)
Edit 2.0 The join is fine is just that 'foo' may change on request to 'foobar' and I don't want to haul through the queries.