If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Simple database design query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-04-08, 05:33
dark_perfect dark_perfect is offline
Registered User
 
Join Date: Jun 2008
Posts: 2
Question Simple database design query

Hi guys,

Simple question, so i'll try to keep it short.

2 tables as follows :

----------------------------------------------
USERS (user_id, ip_address, user_agent)
Primary Key (user_id)

VISITS (visit_id, user_id, page, time)
Primary Key (visit_id)
Foreign Key (user_id) references USERS.user_id
----------------------------------------------

Ok, firstly : Is there anything obviously wrong with this that could have an impact on performance?

Finally : I've got VISITS.visit_id as a primary key. Would it be better to have the primary key as both VISITS.visit_id and VISITS.user_id?

Many thanks

NOTE : For a little background, USERS records the users who visit a website, and VISITS records what page on the site they visit, and at what time.
Reply With Quote
  #2 (permalink)  
Old 06-04-08, 05:38
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Do you expect your users to only ever access from one location or do you want to record all IPs?
Do you expect your users to only ever visit one page or do you want to record all movement?
The answer to the PK question depends on the answer to the second above question
Reply With Quote
  #3 (permalink)  
Old 06-04-08, 05:46
dark_perfect dark_perfect is offline
Registered User
 
Join Date: Jun 2008
Posts: 2
Hi pootle flump,

Q: Do you expect your users to only ever access from one location or do you want to record all IPs?

A: I don't expect the users to only ever access from one location. I've got some PHP code that stores a cookie on the user's PC with their 'user_id' in it. It expires after a day, after which they are recognised as a 'new' user.
--
Q: Do you expect your users to only ever visit one page or do you want to record all movement?

A: I expect the users to visit multiple pages on the site, with all movement to be recorded. In other words, each hyperlink clicked within the site will record a new entry into the VISITS table.

Hope this helps. Thanks!
Reply With Quote
  #4 (permalink)  
Old 06-04-08, 09:04
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by dark_perfect
Ok, firstly : Is there anything obviously wrong with this that could have an impact on performance?
missing index on page, missing index on time

Quote:
Originally Posted by dark_perfect
Finally : I've got VISITS.visit_id as a primary key. Would it be better to have the primary key as both VISITS.visit_id and VISITS.user_id?
it would be better to do away with visit_id altogether, and declare (user_id,page,time) as the PK
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On