patternsqlMinor
Database Normalization - Can one field point to another?
Viewed 0 times
canfieldpointdatabaseoneanothernormalization
Problem
This may sound like a dumb question, but I am a software developer new to database design... So the concept makes sense to me, but maybe this doesn't carry--
Is it possible for a field in a record in Table B to simply point to a field in a record in Table A?
Example: If I have two tables... one containing a list of all employees and another containing a history of those employees coming and going from the office.
I can establish a relationship between History.EmployeeID and Employees.ID with a foreign key, but that duplicates data. So then History.EmployeeID and Employees.ID would contain the same ID number which would be stored in memory twice. So if I went into the database and changed John Smith's employee ID, I would need to write a script or something to scour the database and do a find/replace for that ID.
What I want is for Employees.ID to contain the real ID and History.EmployeeID to simply contain a pointer to Employees.ID. That way, if I updated John Smith's ID, the change would be centralized to one field in one table.
Is this possible?
Thanks
Is it possible for a field in a record in Table B to simply point to a field in a record in Table A?
Example: If I have two tables... one containing a list of all employees and another containing a history of those employees coming and going from the office.
Employees
ID
First Name
Last Name
History
Event ID
Event Time
Event Type (Entry/Exit)
EmployeeIDI can establish a relationship between History.EmployeeID and Employees.ID with a foreign key, but that duplicates data. So then History.EmployeeID and Employees.ID would contain the same ID number which would be stored in memory twice. So if I went into the database and changed John Smith's employee ID, I would need to write a script or something to scour the database and do a find/replace for that ID.
What I want is for Employees.ID to contain the real ID and History.EmployeeID to simply contain a pointer to Employees.ID. That way, if I updated John Smith's ID, the change would be centralized to one field in one table.
Is this possible?
Thanks
Solution
Even if SQL were to support a "pointer" like you describe, the pointer itself would take some memory. Ironically, the pointer might even be larger than the integer value it points to.
You tagged this question with MySQL, so I'll answer with respect to MySQL: there is no support for this pointer concept. In a relational database, columns contain values, not pointers.
Constraints are part of the table's metadata, and serve to make sure the value in the foreign key column does not get out of sync with the key column it references. Either it block changes, or duplicates changes if you declare the foreign key constraint with cascading effects.
Other implementations of RDBMS might have this feature, but not MySQL.
You tagged this question with MySQL, so I'll answer with respect to MySQL: there is no support for this pointer concept. In a relational database, columns contain values, not pointers.
Constraints are part of the table's metadata, and serve to make sure the value in the foreign key column does not get out of sync with the key column it references. Either it block changes, or duplicates changes if you declare the foreign key constraint with cascading effects.
Other implementations of RDBMS might have this feature, but not MySQL.
Context
StackExchange Database Administrators Q#68700, answer score: 7
Revisions (0)
No revisions yet.