4 Replies - 6700 Views - Last Post: 01 May 2012 - 02:28 PM Rate Topic: -----

#1 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 926
  • View blog
  • Posts: 3,205
  • Joined: 19-January 10

Which one should I use?

Posted 01 May 2012 - 12:41 AM

So say I have two tables. Users and Sites.

Users contains user information for those registered on my site. They have a unique ID (auto increments) and a unique username.

Sites contains site information for my users (building a website creator thing).

Now - I want to know what user owns what site so under sites I put down a "owner" column. Should I be putting the owner's ID down in there, or his username? Is there a correct way to do it or is it just a matter of preference?

Is This A Good Question/Topic? 0
  • +

Replies To: Which one should I use?

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9201
  • View blog
  • Posts: 34,573
  • Joined: 12-June 08

Re: Which one should I use?

Posted 01 May 2012 - 07:07 AM

I would suggest using their ID... it's permanent and not subject to change.

Plus if you are in need of the user's name then a simple join gets it..
Was This Post Helpful? 2
  • +
  • -

#3 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 462
  • View blog
  • Posts: 3,161
  • Joined: 12-January 10

Re: Which one should I use?

Posted 01 May 2012 - 07:17 AM

The way we do it at my company is something like this:


Customer Name table-- holds all customer info like email address, name, etc
customer number is unique

user--- holds user info like log in name and passwords

user id is unique

company-- holds the company name
company id unique
Was This Post Helpful? 1
  • +
  • -

#4 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 926
  • View blog
  • Posts: 3,205
  • Joined: 19-January 10

Re: Which one should I use?

Posted 01 May 2012 - 08:08 AM

Yeah, I think I'll go with the user's id. Thanks.
Was This Post Helpful? 0
  • +
  • -

#5 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 795
  • View blog
  • Posts: 1,681
  • Joined: 30-January 09

Re: Which one should I use?

Posted 01 May 2012 - 02:28 PM

Question is pretty much answered, but I'll throw in this gem. JOINing on an int is far quicker than JOINing on a string, so you should try to use int (i.e. - ID) values when FK constraining one table to another.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1