Search code examples
sqlms-accessmagic-numbers

Can you have magic numbers in Access 2007?


How do I store numbers in an Access column and then associate some meaningful string to each value?

Because I don't want to be seeing raw numbers when I can define the meaning of each value once at for all, and have those meanings displayed in the Datasheet View, like:

ID  Name      Type

1   Jack      1 (Friend)
2   Jill      1 (Friend)
3   Diago     2 (Enemy)
4   Sally     3 (Colleague)

Solution

  • You probably want at least two different tables. One that has the ID and Name of the people, and another table with the Type and Description of how they're related to that person.

    If a person can have more than one relationship (e.g. a Friend and a Colleague), you would have a third table that has one column for the ID of the person and another column for the ID of the relationship Type. If a person can only ever have one type of relationship, they you could simply add a third column to your Person table with the ID of the Type of person they are.

    To get data out of the tables, you can use JOINs in your SQL statements to join the rows of all of the tables together by the IDs you have specified for each.

    In general, here's a link that describes what relational databases are all about. Here's a Microsoft Office link that talks about creating relationships between tables using primary and foreign key constraints in Access that might help you out. Here's another with step by step instructions and a fairly relevant example (Students and Grades).