473,480 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Game

49 New Member
Hi all,

Now I have implemented my normalised database with my php code it seems that denormalising would be more efficient :S.

I have 3 tables for my asteroid control.

A main one with information about the user. Like "username"(primary) and resources password etc.

Then there is a table containing asteroids. With "asteroidID"(primary), "type", "mass", "distance"

Then I have a table to assign ownership of asteroids to users. with just 2 fields both primary keys.
"username" and "asteroidID"

There are other tables that link to the "asteroidID" like the mining table indicated which is being mined.

When I come to delete the asteroid is added work with the username to asteroidID link table. Whats the advantage of doing it the way I have which is following normalisation rule over the easier solution which is to remove the link table and put the username field into the asteroid table.?

Thanks
Jul 9 '09 #1
6 1795
Annalyzer
122 New Member
I don't quite understand the thought behind the table linking the user to the asteroid. Does each user get their own personal asteroid?

A linking table is used to provide the solution of a many-to-many relationship. Many users (own? inhabit? destroy?) many asteroids.

If you put the username in the asteroid table, then that asteroid can only be assigned to one user creating a one-to-one relationship. Each one asteroid belongs to one user.
Jul 9 '09 #2
daniel2335
49 New Member
Each user has a variable length set of asteroids that are linked to them, that they scan for and on detection have the ability to select for mining.

Its a 1-many relationship im going for here but normalisation says username shouldn't be in the asteroids table as it doesn't relate to the primary key or something like that. It all gets a little confusing sometimes. random note: Asteroids are destroyed when they have been fully mined.

The options I see to create the one to many is to have the linking table as I currently have. Or to have the username in the asteroid table and have the username and asteroidID both as primary keys.
Jul 9 '09 #3
Annalyzer
122 New Member
Ah, okay. So 1 user has many asteroids. Then, yes, the user does go into the asteroid table. The user relates to the primary key in that the user is the owner of that particular asteroid.

You don't need the table linking them together since you don't have a many-to-many relationship. If each asteroid could be owned by more than one person, then you would need to link them to show ownership.

So, it sounds to me like you want something like this:

tblUser -> username (PK), password, resources, etc.
tblAsteroid -> asteroidID (PK), type, mass, distance, username (FK)

This way, you can delete the asteroid and along with it, the owner, but the username still exists in it's own table.

I hope this helps and good luck!
Jul 10 '09 #4
Atli
5,058 Recognized Expert Expert
Hi.

@Annalyzer
I would have though that would be a one-to-many (1:N) relationship; each user being able to own multiple asteroids.

But yea. If you only want each asteroid to be linked to a single user then you would create a one-to-many (1:N) relationship.
Meaning; putting the PK of the user table into the asteroid table as a foreign key.

If you want each asteroid to be linked to multiple users, then you would need a many-to-many (N:M) relationship, which would require a intermediary table (link table).


I would advise you to use an integer as a PK in your user table, rather then using the username. That way you would only have to put the integer into the asteroid table, rather then the username, which will both safe disk space and speed up your queries.
(String comparison is a lot more complex then integer comparison)
Jul 10 '09 #5
Annalyzer
122 New Member
Atli is right. Putting the username in the asteroid table as a foreign key is a one-to-many relationship. I mispoke in my first post. Hopefully my second post explained it better.
Jul 10 '09 #6
daniel2335
49 New Member
I would advise you to use an integer as a PK in your user table, rather then using the username. That way you would only have to put the integer into the asteroid table, rather then the username, which will both safe disk space and speed up your queries.
(String comparison is a lot more complex then integer comparison)
This sounds like good advice thanks

So the username would be a foreign key not a composite? Was this choice made on the fact the asteroidID can create unique PK's on its own or that username is a primary key in the user table?

I have other tables where there is a nodeNum field that is 1,2,3,4 for each user so as this will repeat for every user I made it composite key with username. Reckon it would be better to have an ID in there to be PK? So then username would be FK, ID PK and nodeNum normal.

Thanks for the good input from both of you given me loads of modifications to make.
Jul 10 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

138
6396
by: theodp | last post by:
--> From http://www.techdirt.com/articles/20040406/1349225.shtml Microsoft Patents Saving The Name Of A Game Contributed by Mike on Tuesday, April 6th, 2004 @ 01:49PM from the...
7
7041
by: Brandon J. Van Every | last post by:
Anyone know of any "good" open source C# game projects out there? Something that actually has a game engine and some content done, so I can just fiddle with it and do interesting / goofy things. ...
1
3677
by: Jerry Fleming | last post by:
Hi, I have wrote a game with python curses. The problem is that I want to confirm before quitting, while my implementation doesn't seem to work. Anyone can help me? #!/usr/bin/python # #...
1
2862
by: fowle040 | last post by:
I underlined and bold print my files. I need to know how to make this code into a working game. The object of the game is to have two players 1- belle and 2-beast. I want them to lose and gain...
7
2815
by: Gasten | last post by:
Hello. The last weeks I've been coding a roguelike (you know, like nethack) in python using the nCurses library. Some week ago I ran into a problem: When I made the object for messagebar-output, I...
5
8911
by: Kraken | last post by:
Hi, i have a bit of a problem here. I have an assignment to do an animal guessing game using an original database and updating it as the user enters new animals in it. The program enters the file...
5
4565
by: alesitaam | last post by:
Help!!!! Im new using python, currently writing a program which tests one game, IQ test. When the module is run, the program should ask user to choose the game to start. Also, I'm using Try...Except...
2
5292
by: LilMeechc20 | last post by:
Hello, I have a group assignment that I have to do. We have to write a Tic Tac Toe game. One person in my group has managed to write the code for a multiplayer (human -vs- human) game and I...
0
7044
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7084
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6739
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4779
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.