473,499 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

More Database Design

49 New Member
There are 3 tables ships, battlegroup, battle_ship.

Each user has 4 battlegroups and each battle group can contain any of the available ships and various quantities of those ships.

Ships
ShipID PK
Armor
Shields
etc
etc

BattleGroup
BattleGroupNum PK
UserID PK/FK
Location
Destination
Strategy

Battle_Ship
BattleGroupNum PK/FK
UserID PK/FK
ShipID PK/FK
Quantity

I'm not sure about if using a compesite key is the best thing to have linking in a many:many.

As if 1000 user each has 4 battlegroups with each battle group having 20 different types of ship in, then thats 80000 rows in Battle_Ship table so less fields the better in there?

If I have a single pk link it would mean an exta field in BattleGroup table. Eg

Ships
ShipID PK
Armor
Shields
etc
etc

BattleGroup
BattleGroupID PK
UserID FK
BattleGroupNum
Location
Destination
Strategy

Battle_Ship
BattleGroupID PK/FK
ShipID PK/FK
Quantity

Thanks in advance.
Jul 15 '09 #1
9 1983
Annalyzer
122 New Member
I don't know the "right" answer here, but I would base my decision on how I was going to refer to the Battle_Ship in future code. For example, say Fred is the player and Fred has the following battlegroups: BG1, BG2, BG3, and BG4. If BG1 contains an aircraft carrier (AC), a cruiser (CR), and 2 destroyers (D1 and D2), then it would make more sense to me to write code that used BG1/AC to refer to the aircraft carrier in battlegroup 1 and BG1/D2 to refer to the second destroyer in battlegroup 1 than to use some arbitrary primary key that didn't describe which ship/battlegroup I was really talking about.

Of course, I get lost easy so I like to use naming conventions that mean something later on down the road. =)
Jul 17 '09 #2
daniel2335
49 New Member
I think that will create more work as if there are 20 types of ship then their would be 20 many:many tables and Id have to query all 20 of them to discover all the ships BG1 has.

Humph database design is so difficult :p
Jul 17 '09 #3
Annalyzer
122 New Member
No, that would make 1 table with 20 records.
Jul 18 '09 #4
Atli
5,058 Recognized Expert Expert
@Annalyzer
This is all dynamic, so there should never be any need for you to actually refer to the data by ID (or a name) in the code.

All you would be doing, by using "BG1/D2" to refer to a battle-group<->ship relationship, is replace two 8byte integers with varying amounts of text, which will increase it's size and query times considerably without any gain at all.


The first design posted is pretty close to what I would do.

Except, I would not include the UserID in the BattleGroup table primary key.
Ideally, the PK would be a Auto_Increment'ed integer, and the UserID a foreign key integer.

I would also remove it from the link table (Battle_Ship).
As the UserID is already in the BattleGroup table there is no need to include it here. The tables can easily be joined if there is need for that.

So, something more like:
Expand|Select|Wrap|Line Numbers
  1. Ships
  2.   ShipID PK
  3.   Armor
  4.   Shields
  5.   etc...
  6.   etc...
  7.  
  8. BattleGroup
  9.   BattleGroupID PK
  10.   UserID FK
  11.   Location 
  12.   Destination
  13.   Strategy
  14.  
  15. Battle_Ship
  16.   BattleGroupID PK/FK
  17.   ShipID PK/FK
  18.   Quantity
  19.  
This would obviously allow for more than four groups per user, but that sort of limitation should be enforced by the application code anyways, not the database.

Storing the battle-group number would be redundant, as you could just count the groups owned by a user ID to get the total count, and select them ordered by the group ID to get them in order. (Which your application could then assign indexes to, based on the positions in the result table... or simply use the given ID returned by the database.)
Jul 20 '09 #5
daniel2335
49 New Member
The UserID was in the link table as it was part of the composite key but it didnt feel right doing it like that.

The battlegroup numer may have to be added as im not sure if im going to allow dynamic create and destrustion of battlegroups which would mess up ordering by group ID.

Unless the user gets 4 rows created in battlegroup table on register and then they are hidden according to research and not deletable. Yeah that will work. :)

I am worried about the potential size of the link table assuming an optimistic 1000 users with 4 groups and 20 ships in each group. Thats 4000 rows in battle group but 800,000 in the link table. Left joining these (the approach i plan to take) to get the information will take a life time to search all those records.

Thanks for the design mod, it looks usable now :)
Jul 21 '09 #6
Atli
5,058 Recognized Expert Expert
@daniel2335
What do you mean by this?
Why would the order of the group ID's matter?
@daniel2335
Wouldn't that be 80.000 rows?
1000 users * 4 groups * 20 ships == 80.000 entries.

Either way, I wouldn't worry about the size of the link table. By designing it to use only integer keys, even tho there are millions of records the size and query speed should remain relatively light.
Neither 800.000 nor 80.000 rows in the link table would cause any sort of performance or storage problem on any half-decent server.
Jul 22 '09 #7
daniel2335
49 New Member
If the BattleGroup ID's generated for a user are 1, 2, 3 that that relate to battlegroup 1, 2, 3. If I delete BattleGroup ID 1 then it will assign ID 2,3 to Battlegroup 1 and 2 but that should be 2 and 3.

Sorry made error in calculation.

I'm also thinking about adding another 2 fields to battle_ship to allow for production of ships (bquantity, start_time).
Which gives the build start time and quantity of building ships. When i come to use the table I can see how much time has passed since start time and the production time of each ship based on that I can move the approprate number of ships from build quantity into the normal quantity field and update the build start time. But they are all int values so should be all peachy.

The only problem with that is those two fields are redundant if there arnt ships being built. Other option would be to have a table very similar to battle_ship but that would probably make more work when it came to query as to find out how many ships there currently were I'd have to get the quantity from one table then find out if enough time has passed in the other table to have produced more ships.
Jul 22 '09 #8
Atli
5,058 Recognized Expert Expert
@daniel2335
I don't follow your logic here.

If you create three groups for a user, and ID #1 in the table has already been used, then the three new groups would be assigned ID's 2, 3 and 4.

You don't pre-assign ID numbers and insert them into the table, you insert the rows and have MySQL assign them ID's.

... I'll come back to the other thing later. Got to run.
Jul 22 '09 #9
daniel2335
49 New Member
But if I was to allow the facility to delete and recreate battlegroups, and if battle groups are assigned in ID order. Then if I delete and then recreate battlegroup 1 because its ID is now after other battlegroups the user has it will assigned as a different battlegroup number and the others will be shifted along with what was battlegroup 2 becoming battle group 1. But I have decided not to allow deletion and creation of battlegroups.

I think im also going to need another table as I was speaking against above because it is probably best if ships are built into a default area and not a battleground as these may not be at home. The user can then move ships to battlegroups.

Expand|Select|Wrap|Line Numbers
  1. Ships 
  2.   ShipID PK 
  3.   Armor 
  4.   Shields 
  5.   etc... 
  6.   etc... 
  7.  
  8. BattleGroup 
  9.   BattleGroupID PK 
  10.   UserID FK 
  11.   Location  
  12.   Destination 
  13.   Strategy 
  14.  
  15. Battle_Ship 
  16.   BattleGroupID PK/FK 
  17.   ShipID PK/FK 
  18.   Quantity 
  19.  
  20. User_Ship 
  21.   UserID PK/FK 
  22.   ShipID PK/FK 
  23.   BuildQuantity
  24.   BuildStartTime
  25.  
  26.  
The new table would allow ships to be stored in a sort of limbo for the user to move around and would also hold the 2 fields required to track building of new ships.
Jul 23 '09 #10

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

Similar topics

116
7413
by: Mike MacSween | last post by:
S**t for brains strikes again! Why did I do that? When I met the clients and at some point they vaguely asked whether eventually would it be possible to have some people who could read the data...
4
3006
by: Steve Jorgensen | last post by:
I'm restarting this thread with a different focus. The project I'm working on now id coming along and will be made to work, and it's too late to start over with a new strategy. Still, I'm not...
1
1407
by: ILCSP | last post by:
Hi,this has been bothering me for a while now. I have 2 MS Access 2000 databases, the real one that everybody uses (in the NT network) and the one I use to design new stuff. After I test the new...
5
3276
by: tHeRoBeRtMiTcHeLL | last post by:
Well, I think I have bitten off a little more than I can chew (at least all at once), and I'm only trying to hammer out tables/relationships at the design level. Which translates to "Seasoned...
5
9607
by: trynittee | last post by:
Hello, It's been a while since I've posted. I am an intermediate user of Access. I can read simple VB code, have done complex queries, comfortable with event procedures, designing forms and...
6
1271
by: Dwight | last post by:
Hi all, This is my first time using a database. I am using Access 2003. I want to design a database for extracting marriage data from our county marriage records. There are four sections with a...
3
2471
by: vicky | last post by:
Hi All, Can u please suggest me some books for relational database design or database modelling(Knowledgeable yet simple) i.e. from which we could learn database relationships(one to many,many to...
3
2094
by: myemail.an | last post by:
If I need to format how the content of a field is displayed, I can click ALT + ENTER from design view, and specify the format, for example, the number of decimal digits and so on. Is there a way...
1
2325
by: abhijitbkulkarni | last post by:
Hello, I am designing a .NET database application that uses 3 tier architecture. Starting initially, this application will be desktop application but I will convert it into a website later but...
0
1883
by: sam | last post by:
Hi, Hope you are doing well !!!! One of our clients is looking to augment their team with “Database Architect – DB2" please find below the details and respond with
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7012
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
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
7225
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...
0
4605
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
3105
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
3101
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
307
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.