构建数据库抽奖网站的有效方法[关闭]

I'm planning to make some kind of a raffle site as part of some gaming site. Now I was brainstorming about the best way to structure the database where the different raffles are stored. So my idea is to create a row for each raffle and give each ticketnumber its own column (which will hold the userid of the owner of the ticket). But as a raffle can get up to 1500 tickets I doubt if this is the best way to structure the table. Does anyone has another (better) suggestion how to do this or is this the best way?

I would suggest having two tables. One called raffle which holds the raffle information for the current raffle and one called raffle_ticket holding the ticket information for the raffles. Here is the following structure I propose:

raffle columns:

  • raffle_id (Auto increment primary key)
  • raffle_name (Raffle name)
  • raffle_date (date of raffle)
  • .... Other raffle information

raffle_ticket columns:

  • raffle_ticket_id (Auto increment primary key)
  • raffle_id (Foreign key linking to the raffle_id in the raffle table)
  • raffle_user_id (Foreign key linking to the user_id in your user table)
  • raffle_num (The number of the ticket in the current raffle (Can be generated with SELECT MAX(raffle_num)+1 as newrafflenumber FROM raffle_ticket WHERE raffle_id = CURRENT_RAFFLE_ID; if you want sequential numbers per raffle)

You may need something slightly different, but that's what I would suggest.