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 > Primary Key Issues

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-08-07, 12:27
Matt_B Matt_B is offline
Registered User
 
Join Date: Jan 2007
Posts: 1
Question Primary Key Issues

I am creating a database that by it's nature will be used locally and syncronised with a central copy whenever possible.

To retain integrity Primary Keys will be generated by auto-incremented added to the username of the person adding the record, my problem is how to store this.

Using 2 Fields seems wasteful or untidy. The alternative that I can see would be to combine them into a single field, this again doesn't seem to be a very nice way of doing things.

I'm guessing that I am being pedantic, and that creating a single field would be the best option.

Any thoughts?

Cheers
Matt
Reply With Quote
  #2 (permalink)  
Old 01-09-07, 00:55
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
If you are concerned about keeping the IDs unique across distributed databases, use a GUID as a primary key instead of an integer.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
  #3 (permalink)  
Old 01-09-07, 07:22
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
if you stay with the username plus autonumber, keep them as separate fields
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 01-09-07, 11:54
loquin loquin is offline
Super Moderator
 
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,797
Note that an autoincrement/sequence/identity field is unique, by itself. The name field would not be required for uniqueness, and is thus redundant to be included as a part of the PK.
__________________
Lou
使大吃一惊
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert

Reply With Quote
  #5 (permalink)  
Old 01-09-07, 12:00
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
yes, but loquin, what if the database will be "syncronised with a central copy whenever possible"

if todd creates rows 1, 3, and 5 in his local database, and mary creates rows 2, 4, and 5 in her local database, what happens when these rows are brought into the central database?

hence the need for an additional column in the primary key
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 01-09-07, 12:18
loquin loquin is offline
Super Moderator
 
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,797
Quote:
Originally Posted by r937
yes, but loquin, what if the database will be "syncronised with a central copy whenever possible"

if todd creates rows 1, 3, and 5 in his local database, and mary creates rows 2, 4, and 5 in her local database, what happens when these rows are brought into the central database?

hence the need for an additional column in the primary key
D'oh! missed that.
__________________
Lou
使大吃一惊
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert

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