Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

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, 06: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, 06:38
pootle flump pootle flump is offline
COLOSSAL WIN
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 10,342
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, 06: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, 10:04
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,539
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

pre-order my book Simply SQL from Amazon
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

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