Guy Emerson wrote:Hi all,
In a recent interview I was given a scenario wherein there is a database which contains millions of records even duplicate records as well. Now in a java program if we access these records, how would I ensure that the data I am accessing is not duplicate?
They provided a hint that Maps can be used, or may be hashcode() method!!
Now the question is how?
Thanks
The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
Pavan Kumar Dittakavi wrote:
2. Database schema not having a primary key:
In this case, since the db does not have a primary key..what should be the KEY for the map?. Surely this is something that can't be determined.
So, the appropriate way for doing this should be at the query level.
Pavan Kumar Dittakavi wrote:I have one question here. With a hashmap, you can have a key that points to the value. And we can have two cases in this problem.
1. Database schema having a primary key:
In this case, we can capture the primary key of the database in the KEY position of the map. In this case, to be honest there wont be a need for KEY as a db having a primary key ensures that no duplicate records are stored in it. So, this case is handled automatically.
2. Database schema not having a primary key:
In this case, since the db does not have a primary key..what should be the KEY for the map?. Surely this is something that can't be determined.
So, the appropriate way for doing this should be at the query level.
[ Experts please drop your views on this one ].
Thanks,
Pavan.
Campbell Ritchie wrote:Welcome to the Ranch
Alok Aparanji
Alok Aparanji wrote:
For the second point, there can be several reasons why the DB might not have a primary / unique key
1) There is a column which is actually unique but is not declared to be the primary key.
2) The DB might be de-normalized for performance reasons.
You have to be odd to be #1 - Seuss. An odd little ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
|