Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8758493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:33:47+00:00 2026-06-13T14:33:47+00:00

I am a sophomore computer science student at a university. I’m making a online

  • 0

I am a sophomore computer science student at a university. I’m making a online app with php/mySQL. This is my first experience with both PHP and mySQL. Anyway I am making an app that keeps track of baseball games. The user creates a team of players and starts a game against another team, the user enters in outcomes while the app scores the game and keeps player stats. I am designing the database and was hoping someone could clarify for me:

Primary Key-
I am pretty sure I understand what this is. Basically its the unique identifier of each row, used for distinguishing each row.

Foreign Key-
Right now I have a “Players” table, I also have a “PlayerStats” table. If I understand it correctly (which I probably don’t) the “Players” table has a column “playerStatsId” which is the primary key of the “PlayerStats” table. This works because there would only be one stats table per player.

No key???- Ok so heres my example. Each user of my app should have the ability to add as many teams as they want to the database. They can only edit the games of a team that they “own”. I was thinking I could accomplish this by having a table with two columns: “username” and “teamId”. Then I could search through the table and pick out the teams that belong to a certain user. I don’t feel like this is the answer because it doesn’t seem very efficient. Is there a better way?

I am grateful for any help! Thank you!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:33:48+00:00Added an answer on June 13, 2026 at 2:33 pm

    The player table should have it’s PK in the PlayersStats table as a FK. You could relate it either way, but it makes more sense to have an aspect of the player be the foreign key side of the relationship.

    As far as “no key”, you should try to avoid this. In a relational database, if there’s a relationship, you should make that explicit. You avoid having orphan rows this way. An orphan row will basically be a piece of data that, through no relationship, can just sit forever and clutter your Db. In this case, your User table should have a PK and that PK should be what links it to the Teams table. You can have two columns, but one of them should relate to the user table. Your Team table should have a PK acting as a FK in any player’s table as well, as those players belong to teams.

    I would also Key the Team table as well. You should never assume a database is ever finished, even if it’s your own. Write code/databases with the intention that they will expand.

    There is a lot more to this, I am sure. But these are some general points to get you started.

    EDIT:

    Seeing the comment in your question: if users can have multiple teams, you may want to have a table between the user and team table with the UserId and TeamId as FK’s. This may be a table you don’t have to key as deleting a user or team should cascade (or error) through that linking table.

    So:

    Player(PK)->(FK)PlayerStats
    --if multiple users can have multiple teams
    User(PK)->(FK)LinkTable(FK)<-Team
    --if 1-1 user-team
    User(PK)->(FK)Team
    Team(PK)->Player(FK)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings all, I am currently a rising Sophomore (CS major), and this summer, I'm
I'm normally pretty efficient at solving PHP problems all by myself, however with this
<?php $host=localhost; // Host name $username=root; // Mysql username $password=; // Mysql password $db_name=ureviewdu;
Hey everyone, this is my first post up on StackOverflow! WOO! Anyhow, onto my
public void button2_Click(object sender, System.EventArgs e) { string text = textBox1.Text; Mainform = this;
I have the dataframe test <- structure(list( y2002 = c(freshman,freshman,freshman,sophomore,sophomore,senior), y2003 = c(freshman,junior,junior,sophomore,sophomore,senior), y2004
I'm learning the OO and MVC paradigm (using Codeigniter and PHP). I continue to
I am new to app programming, and programming in general. I am still in
I have the dataframe test <- structure(list( y2002 = c(freshman,freshman,freshman,sophomore,sophomore,senior), y2003 = c(freshman,junior,junior,sophomore,sophomore,senior), y2004
I have the dataframe test <- structure(list( y2002 = c(freshman,freshman,freshman,sophomore,sophomore,senior), y2003 = c(freshman,junior,junior,sophomore,sophomore,senior), y2004

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.