I am creating a banking database and I have the following problem here.
Suppose CustomerA has an Account Number 4444 and through this I access all details related to the the customer I have a separate primary key but I generally query on this Account Number.
Now, for some reason the Account Number of CustomerA is changed from 4444 to 5555 and a new CustomerB is given the Account Number 4444.
I want my database to handle such a change, what approach should I apply?
Approaches I developed are: assigning a timestamp with the account number, this will help me to query efficiently to find out the current Account Number related Customer Name.
But I cannot design a query in which:
I'm going to assume this is an educational exercise rather than a real banking application.
It doesn't really make sense to identify customer information with an account number alone. Customers can have more than one account and accounts can be held jointly by several customers, so an account number is unlikely to be a suitable key for customers. I suggest you create a customer number for that purpose.
I seriously doubt that any bank would be imprudent enough to allocate old account numbers to new customers. Just possibly that might happen after many years have elapsed since an account number was last used but it's probably not something you need to anticipate in your database design. Similarly, I would not expect to delete or overwrite customer account numbers because account details, including account numbers, are normally kept for years (probably decades).