jeudi 27 avril 2017

Design SQL Server database correctly

I have simple registration form, but there are 3 checkboxes for example:

Name:   [        ]
Email:  [        ]
Pass:   [        ]
What do you like at free time?  
  Reading:    [ ]
  Travelling: [ ]
  Sport:      [ ]

As in example above you see "What do you like at free time?" There are 3 checkboxes. There are multiple options, people could check only Reading checkbox or Reading and Travelling or all checkboxes, etc.

How to store it correctly in the database?

For example If I'll create Users table in following:

CREATE TABLE #User
(
    Id INT IDENTITY,
    Name NVARCHAR(60),
    Email NVARCHAR(60),
    Password NVARCHAR(60),
    FreeTime INT
)

I could insert only 1 choice from checkbox. Comma separated solution is bad practice.

I don't know If It's good practice in users table insert multiple records with the same UserId to insert all checkboxes values as separate rows?

Or better way to create new table FreeTime something like?

CREATE TABLE #FreeTime
(
    Id INT IDENTITY,
    UserId INT,
    Description NVARCHAR(60)
)




Aucun commentaire:

Enregistrer un commentaire