I’ve been given the task of combining 7 databases into one legacy system that will only hold static data.
So what I want to do is add a prefix of two letters to the identity field of each table so that I can see by the ID of which database it originally came from e.g.
StaffID = 1 in the old database, in the new single database I want it to look like this StaffID = AB1. This is also to get rid of the problem of users in all seven databases having the same StaffID (Along with other ID Fields).
Is there a quick and easy way of doing this? Or do you guys think there is a better solution?
Cheers!
Quick and easy; not really. If you want to update the existing IDs, instead of creating a new column to refer to:
First, you’ll need to change any ID fields that are numeric (
int, etc.) into avarcharfield to hold the new key. Thevarcharwould need to be of an appropriate size to hold the largest ID plus the prefix.You would also need to convert any foreign key fields from a numeric field to a varchar field of an appropriate size.
Finally, you would need to import the data into the new database, appending the prefix to any primary keys and foreign keys.