• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

database unique fields

 
friso dejonge
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
First of all, i've read loads of comments on the javaranch, and i have to say it is a very good and helpfull resource.
After reading some questions on database, am I right to assume that on this occasion the flightnumber is the unique key in the database for each record. I do know, that in real life this is not the case, but the find function in Data class, uses the first arrayfield (values[0].equals(toMatch) as a right match. Also the add method checks on this key to verify if there are duplicate keys. So can anyone confirm the flightnumber is the unique key. ?
thanks,
friso
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, yes and no. Good Answer Mark.

Yes you use the find methods by passing the flight number, and we hope that it is unique. And in the case of the records currently in db.db file it is unique. And the assignment does not have us add any more flights, so therefore it is unique. But let's say down the road they want that to change, so then it won't be the primary key.
I think they added it that way because it makes the assignment easier for us to just get the first field and pass it to find and it finds the record for us.
To me record number is the only guaranteed unique number for the db file.
Mark
 
friso dejonge
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
true, but even when adding records, it is enforced that the flightnumber is unique. So if at a later stage they change the uniqueness, then code for adding, and finding has to be changed as well.
If I add this in my assumptions/considerations...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic