I have a database that has two tables, these tables look like this
codes id | code | member_id 1 | 123 | 2 2 | 234 | 1 3 | 345 | 4 | 456 | 3 members id | code_id | other info 1 | 2 | blabla 2 | 1 | blabla 3 | 4 | blabla
the basic idea is that if a code is taken then its member id field is filled in, however this is creating a circle link (members points to codes, codes points to members) is there a different way of doing this? is this actually a bad thing?
Update
To answer your questions there are three different code tables with approx 3.5 million codes each, each table is searched depending on different criteria, if the member_id column is empty then the code is unclaimed, else, the code is claimed, this is done so that when we are searching the database we do not need to include another table to tell if it it claimed.
the members table contains the claimants for every single code, so all 10.5 million members
the additional info has things like mobile, flybuys.
the mobile is how we identify the member, but each entry is considered a different member.
It’s a bad thing because you can end up with anomalies. For example:
See the anomaly? Code 1 references its corresponding member, but that member doesn’t reference the same code in return. The problem with anomalies is you can’t tell which one is the correct, intended reference and which one is a mistake.
Eliminating redundant columns reduces the chance for anomalies. This is a simple process that follows a few very well defined rules, called rules of normalization.
In your example, I would drop the
codes.member_idcolumn. I infer that a member must reference a code, but a code does not necessarily reference a member. So I would makemembers.code_idreferencecodes.id. But it could go the other way; you don’t give enough information for the reader to be sure (as @OMG Ponies commented).