0

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 e.g. 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.

E.G:
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

5
  • "The scenario is: I have a user who can be in ONE AND ONLY ONE city at a time." Try using DISTINCT. Commented May 8, 2014 at 13:35
  • Are you asking how to build the tables and relationships to handle this scenario? If you are limited to working with a schema that has already been built, please share the definitions for the User (player), City and Area tables. Commented May 8, 2014 at 13:41
  • It would most certainly NOT be more efficient to create a separate table for each city. Commented May 8, 2014 at 13:42
  • SELECT * FROM rooms_$playerCity WHERE roomID = $playerRoom beware of SQL injection Commented May 8, 2014 at 13:43
  • @ImreL I would use the proper escaping sequences etc to prevent injection. bisvel I'm not stuck to an existing schema it's a new system I'm building Commented May 8, 2014 at 14:12

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

I never came across partioning before.
0

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
    ...
    )

enter image description here

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.