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.

No comments:

Post a Comment