-3

I am creating a website that will have a database containing a list of games. There will be several different types of games.

I'm looking at a SQL Server entity relationship diagram for reference, but I'm wondering about the part I pasted below:

  • Why would GAME_TYPE be its own table rather than a part of "Games" Table?

  • What is the purpose of having GAME VARCHAR(MAX) under GAME_TYPE Table?

GAMES Table (Contains a listing of all games):
GAME_ID INT IDENTITY (1, 1)
GAME_TYPE_ID INT
GAME VARCHAR(MAX)
CONSTRAINT (GAME_TYPE_ID) REFERENCES GAME_TYPE(GAME_TYPE_ID)

GAME_TYPE Table (Contains a list of all game types):
GAME_TYPE_ID INT IDENTITY (1, 1)
GAME VARCHAR(MAX)

Just trying to get some clarity on the logic of SQL Server database designs.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
m0a
  • 1,005
  • 2
  • 15
  • 29
  • You have created two seperate table i.e games and game_type and Varchar(max) stores a maximum of 2 147 483 647 characters – Bananas Jan 07 '19 at 11:56
  • Where did you get this? What does the specification or documentation say? We can only guess from table & column names & types. Presumably games column game is the name of a game identified by column game_id & game_type column game is the name of a game type identified by column name_type_id. Nobody can interpret or update a database without being told how to by the designer. Why are you asking us? (Maybe the columns you call "game" are actually "name"?) – philipxy Jan 08 '19 at 11:18

1 Answers1

1

The point of making a seperate table for game types is that you can use foreign keys to set game types per game, if you have a game_type value in your GAMES table, which in this case is GAME_TYPE_ID.

As for the Varchar(MAX), the MAX allows infinitely long strings. This article here talks more about Varchar(MAX) vs TEXT tags. Why not use varchar(max)?

  • A 2GB string isn't infinitely long. – Dan Guzman Jan 07 '19 at 12:22
  • Thank you. But why is the `GAME VARCHAR(MAX)` line in there at all? What is its purpose, why is it in the GAME_TYPE table? – m0a Jan 07 '19 at 17:46
  • @matthew - You're asking questions related specifically to relational data modeling and normalization (which will pretty much clear things up for you). I'd suggest spending some time studying normalization, rather than asking people to explain this particular table schema. – David Makogon Jan 08 '19 at 11:45