| |
|
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.
|
 |

01-08-07, 12:27
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 1
|
|
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
|
|

01-09-07, 00:55
|
|
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"
|
|

01-09-07, 07:22
|
|
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
|
|

01-09-07, 11:54
|
|
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
|
|

01-09-07, 12:00
|
|
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
|
|

01-09-07, 12:18
|
|
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
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|