1

To preface this question I should say I know very little about database efficiency which will become glaringly apparent very shortly.

This is a fairly simple question:

I'd like to store attendance to events within a mysql database. I've thought of two possible methods (there are more, I'm sure):

  1. Create an additional attendance row in the events table, containing a comma separated list of user ids
  2. Create an attendance table, containing two columns, event_id and user_id

My instinct says that method 2 would be the most efficient -- although multiple rows would have to be returned and traversed, this is likely less costly than searching for a particular user_id within a concatinated string...

Can anyone confirm this?

1
  • P.S. any other options are also welcome! Commented May 23, 2012 at 21:19

2 Answers 2

3

create a new table!

Otherwise you are not taking advantage of the relational aspect of MySQL and every query you run will have to parse the results of the csv entries (horrbily inefficient)

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

Comments

1

The second option is better. Searching in a comma separated string is time consuming.

However in the 2nd option, make sure the event_id and the user_id are FOREIGN KEYS.

This will INDEX the columns and you will have better searching results.

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.