Showing posts with label game. Show all posts
Showing posts with label game. Show all posts

Monday, March 19, 2012

How to set up my tables

Hi everyone,

I am very new to Sql Server and Visual Basic. I am trying to put together a football game. I need to set up a database full of teams for the game to choose from and match up against one another. I need mulitple teams, each with individual players, positions and ratings. No matter what I do I just cant seem to get this to set up the way I want it to. I want to be able to pick the team from a combobox and the players and ratings for each player appear in the textboxes I have provided. I know this shouldn't be very hard, but I have been stuck on this for months now. Please help!

P.S. I do know how to basically set up a database, assign textboxes to database values and all that. I just basically can't figure out the relationships of tables needed in the database to make this work. Thanks again!

You want 2 tables:

Table 1: tblTeams

-

TeamName Primary Key

TeamID Pimary Key identity

Table 2: tblPlayers

-

PlayerName Primary Key

TeamID

Ratings

Once you have the tables designed, the dropdown can ask the team and display the players or display the player to identify the team.

This will display all players on whichever team is selected

SELECT p.Players FROM tblTeams t

JOIN tblPlayers p on t.TeamID = p.TeamID

WHERE t.TeamName = txtTeam.text

This will display the team that the player is on:

SELECT t.TeamName FROM tblTeams t

JOIN tblPlayers p on t.TeamID = p.TeamID

WHERE p.PlayerName= txtPlayer.text

Hope this helps,

Adamus

|||I'll try that out, thanks.|||

Adding to Adam's presentation, if this is a multi-user 'fantasy football' type simulation, you will be presented with multiple users creating 'their' individual Teams. As well as each Team containing multiple Players, A particular Player can exists on multiple Teams.

In that situation, it may be helpful to allow Players to be select to multiple teams, so in addition to Teams and Players, a Team-Player table would likely be useful.

Friday, February 24, 2012

How to set a relationship here?

How to create a relation between gf_game and gf_gamegenre here? gf_gamegenre is responsible for the relation between a game and it's genre(s). The relationship between gf_genre and gf_gamegenre worked. (http://img361.imageshack.us/my.php?image=relationzl9.jpg)

When I try to set a relationshop between gamegenre and game I'm getting this error:

'gf_game' table saved successfully
'gf_gamegenre' table
- Unable to create relationship 'FK_gf_gamegenre_gf_game'.
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_gf_gamegenre_gf_game". The conflict occurred in database "gamefactor", table "dbo.gf_game", column 'gameID'.

Thanks for any help!

Shouldn't gf_gamegenre have a composite primary key of genreID and gameID? Then you would link gf.genreID with gf_gamegenre.genreID and gf_game.gameID with gf_gamegenre.genreID