DataBase table Design
Hello Every one!!
I want to create a database for storing Messages sent to user.I did'nt posted this in database section, because i though it's too basic for that place.
so how to design it so that i can fine the messeges from userId, do i need to alot a Unique id to each message??
Can you tell me the most efficient way to create such a table.
Well, depends on wether you are trying to connect to an actual database (MySQL, Oracle, SQLite, etc...) or are just kinda 'making your own'.
If the first case, you can use one of the java database connectors, but you will need to have the database up and running first.
In the second case, there are MANY ways to do this. This is really a data structures question. You can approach it several ways:
If every user has a Name, ID pair, then anything from a simple array to a HashMap would work.
You need to identify key goals:
- Do you need to do lookups by name?
- Do you need to be able to search the list of users by name efficiently?
- Do you need to be able to do partial string searchers (search for 'rob' to finder 'Robert Johnson')
- Do you need to be able to search the list of messages for each user?
- Does any of this need to be sorted?
The answers to these questions help determine what structures you need to use. Arrays are simple, but are unsorted and are slow to search. HashMaps are fast to lookup, but you must know the Key to get the Value, and you cannot do it the other way around (Value to find Key).
An OOP approach might be the simplest to visualize (A User class, MessageList class, etc..) but might not be the most efficient. Can you clarify?