What is the best approach to linking tables when thinking about performance and data integrity.
for example, lets say I have a column of type char, and it is a primary key that has a relationship with another table on a column of the same type. Since an index is created between the two tables, is the efficiency of searches between those tables based on the index or the char strings themsleves.
Right now I have an extra column on my tables that is of type numeric called ID. I have this ID in both tables and I base the relationship between the tables on this number. This numeric field really gives no info other than linking the tables becuase the real info I care about is a char field that, as of now, I consider inefficient to place on all tables and base my SQL searches on.
So, the 2 major issues I am concerned about are:
1. Should I eliminate this extra numeric column becuase the indexing of the char fields themselves will perform just as well, and
2. Is having this numeric column unsafe in the case of relationships? If by some system error or user error if we lose an important table we may lose the connection of the numeric field and the char field it is representing. therefore we could lose track of what some of our tables are trying to tell us about.
table 1: table2:
name type name type
--------------- -----------------
ID(pk) numeric ------> ID(fk) numeric
serialnum char task char
Location char date datetime
so the central item is the serial number(ex: 'SN365676')
would I rather have that in every table? or is the ID a better link that would perform better.
Is this good practice? If we lost table 1, table 2 loses any meaning.
Thanks for any help you can give,
Marc
for example, lets say I have a column of type char, and it is a primary key that has a relationship with another table on a column of the same type. Since an index is created between the two tables, is the efficiency of searches between those tables based on the index or the char strings themsleves.
Right now I have an extra column on my tables that is of type numeric called ID. I have this ID in both tables and I base the relationship between the tables on this number. This numeric field really gives no info other than linking the tables becuase the real info I care about is a char field that, as of now, I consider inefficient to place on all tables and base my SQL searches on.
So, the 2 major issues I am concerned about are:
1. Should I eliminate this extra numeric column becuase the indexing of the char fields themselves will perform just as well, and
2. Is having this numeric column unsafe in the case of relationships? If by some system error or user error if we lose an important table we may lose the connection of the numeric field and the char field it is representing. therefore we could lose track of what some of our tables are trying to tell us about.
table 1: table2:
name type name type
--------------- -----------------
ID(pk) numeric ------> ID(fk) numeric
serialnum char task char
Location char date datetime
so the central item is the serial number(ex: 'SN365676')
would I rather have that in every table? or is the ID a better link that would perform better.
Is this good practice? If we lost table 1, table 2 loses any meaning.
Thanks for any help you can give,
Marc