The Syndk8 - Black Hat SEO Paradise
Fantomaster - Industrial Strength Black Hat SEO Tools
Affiliate Earners: Affiliate Programs
Home
Help
Search
Login
Register
RSS for SEOIdiot
Welcome,
Guest
. Please
login
or
register
.
July 29, 2010, 07:55:38 PM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home (Index)
Level 1 Cache: General Discussion
All Things Database
Primary Key Selection
Pages: [
1
]
« previous
next »
Print
Author
Topic: Primary Key Selection (Read 229 times)
cdc
Expert
Offline
Posts: 105
Primary Key Selection
«
on:
December 10, 2009, 08:45:47 PM »
This may belong in the n00b section, but I'll post it here anyway.
When setting up my database tables I have always used an auto-increment numeric id field as the primary key.
But now I have a situation where I want to track every visitor that comes to my site. So you hit my page and I want to add a row to my "visitor" table so I cookie you with your ID and store that in my DB.
Now, for obvious reasons, I don't want this ID to be an auto-increment value. So what I am planning on doing is generating the ids with:
md5(uniqid(mt_rand(), true));
and using that (char(32)) as the primary key in my visitors table.
I'll be doing a fair amount of lookups using this value in this table as well as others.
Thoughts? Suggestions?
Logged
Will code for food.
nutballs
Administrator
Lifer
Online
Posts: 5296
DAMN YOU!!!!!!!
Re: Primary Key Selection
«
Reply #1 on:
December 10, 2009, 10:06:41 PM »
generally, I do autoinc int for the PK regardless. So ALL my tables always have that auto inc int PK. The reason why is to speed up subsequent lookups. Or at least that has been my reasoning, since I assume int is faster than char of course.
You could of course do the md5(uniqid(mt_rand(), true)); as UNIQUE index. It doesnt have to be PK. And, that way you can fall down to using the INT for followup lookups.
of course if there is generally going to only be 1 lookup then done with it, then never mind...
Logged
qweqwe
Rookie
Offline
Posts: 14
Re: Primary Key Selection
«
Reply #2 on:
January 12, 2010, 07:23:26 PM »
<spammer dick go boom>
«
Last Edit: January 12, 2010, 08:31:28 PM by nutballs
»
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Level 1 Cache: General Discussion
-----------------------------
=> Init() - New Member Introductions
=> NEW BOARD: The n00b Zone
=> Callback Routines
=> freemem() & Garbage Collection
=> All Things General Tech
=> All Things Apple
=> All Things Database
=> All Things Microsoft
=> All Things *nix
-----------------------------
Level 2 Cache: Speciality Items
-----------------------------
=> AJAX
=> ASP & .NET
=> C/++/#, Java, Object Pascal
=> CSS, HTML & SEO, Cloaking
=> JavaScript
=> Music Technology
=> PERL
=> PHP
=> Obscurites, Curiosities & Arcanity
=> Regex
-----------------------------
Frameworks, Applications & Projects
-----------------------------
=> phpMyIDE
=> The iPhone SMF Theme Project
=> SMF
-----------------------------
Retired Boards
-----------------------------
=> ColdFusion
=> phpMyIDE
=> SalesForce / Apex
=> Javascript Code Repository & Examples
=> PHP Code Repository / Examples
Perkiset's Place Home
Best of The Cache
phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's
Pinkhat's Perspective
cache
mart
coder
programmers
ajax
php
javascript
Loading...