Author Topic: Question about Foreign Keys  (Read 504 times)

Offline 133794m3r

  • Level 22
  • *
  • Posts: 265
  • Reputation: +2/-0
    • View Profile
Question about Foreign Keys
« on: April 22, 2010, 11:06:08 PM »
Ok, my messaging system aka the Mailing sytem is set up a bit like this.
Code: [Select]
id,
senders_id int,
receivers_id int,
message varchar(250),
snipped the random rest of it.

   
Anyway i was wondering if it's possible to have two seperate foreign keys. Since both senders_id and recievers_id are both holding the id of a player which is stored inside of the players table and both are referencing players(id) for their value and various other information. Is it possible to have more than one foreign key and it work well? Or is there some sort of "it's the end of the world" type event that'll come of this?

I'm going to still try it right now after i'm done posting this but i thought i'd ask how it'd all go since i'm going to include a similar thing for the pvp logs/trade logs if it was possible and works fine.

nvm the last things it seems that i forgot to make sure that the id in the other table was unsigned and the rest are the same forgot to cehck for exact matches. The original question remains.
« Last Edit: April 22, 2010, 11:40:23 PM by 133794m3r »

Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Question about Foreign Keys
« Reply #1 on: April 23, 2010, 01:45:30 AM »
Well since you see that it's totally logical here (and IM/messaging system is something really common), I'm certain it's not a problem, but feel free to correct me
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline lolninja

  • Level 19
  • *
  • Posts: 194
  • Reputation: +5/-0
  • BSc powered Programmer
    • View Profile
    • HTTPmmo
Re: Question about Foreign Keys
« Reply #2 on: April 23, 2010, 04:29:50 AM »
Yeah multiple foreign keys is all good, you can even apply multiple indexes for example indexing by senders_id, receivers and a combination of senders_id and receivers_id just remember that the more indexing your doing the slower your inserts will be.
Having multiple foreign keys should but to much of a hit on performance, but with most things in life, if you do to much of something you'll start getting some adverse hits on performance.

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal