I am writing a query to create a database in SQL server 2008 R2. I plan to use it with entity framework in a mvc3 application
I have users, games and highscores.
What I want ot do is this:
I want to create a many-to-many relationship between users and games.
Each User can have multiple games and each game can have multiple users.
and each relation user-game has 1 high score.
So far I created the users, games, highscores tables:
CREATE TABLE Users
(
UserId INT IDENTITY(1,1),
FirstName VARCHAR(64) NOT NULL,
LastName VARCHAR(64) NOT NULL,
Email VARCHAR(200) NOT NULL,
CreatedDate DateTime NULL,
PhoneNumber VARCHAR(32) NULL,
Password VARCHAR(64),
CONSTRAINT pk_users_userid PRIMARY KEY(UserId)
)
CREATE TABLE Games
(
GameId INT IDENTITY(1,1),
Url VARCHAR(64) NOT NULL,
CONSTRAINT pk_gamess_gameid PRIMARY KEY(GameId)
)
CREATE TABLE Highscores
(
HighscoreId INT IDENTITY(1,1),
Value INT NOT NULL,
CONSTRAINT pk_surveyors_surveyorid PRIMARY KEY(HighscoreId)
)
What is the best way to create the many-to-many user-game relation and give each relation one high score? should I create a 4th table to hold the relation? And if I do so will I be able to use the database with Entity framework in an MVC3 application or would that complicate it?
Thank you
Additional note: I am planning to use this database with entity framework in a MVC 3 web application.
1 Answer