I have read many posts on here about this discussion but my question is specific.
Please read in entirety before replying.
I am wondering whether it is best to have potentially hundreds if not thousands of rows in a database or to split it across multiple tables.
The scenario is: I have a user who can be in ONE AND ONLY ONE city at a time. (There are multiple cities eg Paris, Berlin and London) Now in each city are lots of areas (potentially several hundred). I was thinking that giving each city its own table would be more efficient.
EG:
rooms_london
- All areas of london in here as rows
rooms_berlin
- all areas of berlin in here as rows
And so on for Paris and any other cities that I add in future.
Then in PHP I could construct a query similar to:
SELECT * FROM rooms_$playerCity WHERE roomID = $playerRoom
Is this an efficient method or should I just add an extra column to a central rooms table.
If I've not been clear enough I will do my best to clarify anything that you need.
Many Thanks
I would not split rooms into different tables.
If performance becomes a problem I would use partitioning http://dev.mysql.com/doc/refman/5.5/en/partitioning.html
+------+ +------+
| City | 1 ---- * | Room |
+------+ +------+
whether ... thousands of rows in a database or to split it across multiple tables.
performance will not be a problem before few million rows with complex queries and insufficient indexing
I don't use MY SQL but my SQL Server table design would look like this
Create Table Player (
PlayerID int
...
)
Create Table City (
CityID int
...
)
Crate Table Rooms (
RoomID int
CityID int
...
)
Create Table PlayerRoom (
PlayerID int
RoomID int
ChaeckIn DateTime
CheckOut DateTime
...
)
Then to get the last player in a room you could query by
Select Top 1 * from PlayerRoom where Roomid = @roomID order by CheckIn Desc
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.