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 > Database Server Software > MySQL > Variable PK for specific value

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-18-06, 00:48
anjanesh anjanesh is offline
Registered User
 
Join Date: Feb 2005
Location: Mumbai, India
Posts: 161
Variable PK for specific value

This is my table structure
Code:
CREATE TABLE `poll_results` (
  `PollID` bigint(20) NOT NULL,
  `UserID` bigint(20) NOT NULL,
  `OptionNo` int(11) NOT NULL,
  `Entry` datetime NOT NULL,
  PRIMARY KEY  (`PollID`,`UserID`,`OptionNo`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
The reason for `OptionNo` included for PK is to use it for multiple-select polls.

I have the first entry in a `Users` table with UserID = 0 is for Anonymous user.
How do I get this to work such that its
PRIMARY KEY (`PollID`,`UserID`,`OptionNo`) for every `UserID` thats not 0 and
PRIMARY KEY (`PollID`,`OptionNo`) for every `UserID` thats 0.

Thanks
__________________
MySQL 5.1
Reply With Quote
  #2 (permalink)  
Old 12-18-06, 03:08
Yveau01 Yveau01 is offline
Registered User
 
Join Date: Dec 2005
Location: Tilburg, Netherlands
Posts: 73
... by redesigning it. This is not going to work, you can't declare a 'variable' PK. Problem is that you're trying to implement something that is data related. That's wrong, always was wrong and will be wrong in the future. A database design should be completely data unrelated. So using 'special' ID's etc (like your 0 for anonymous users) should not influence the database model.

So my advice: back to the drawing table and try another aproach. This is not going to stand the test of time.

Gr,
Yveau
__________________

> SELECT * FROM users WHERE clue > 0;
Empty set (0.00 sec)

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