![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a person table and want to add an extra 1xM table: tblNotes. I'm doubting whether to add a specific primary key NotesID or to put a primary index over several fields: Solution 1: NotesID* PersonID DateTime_Entered UserID_Entered Note Solution 2: PersonID* DateTime_Entered* UserID_Entered* Note What would be best? Thanks, Lars |
#3
| |||
| |||
|
|
You say 1xM. Therefore, it has to be solution 1. |
|
Besides, if you really wanted to prevent duplicate of #2: |
|
On 5/15/10 6:09 AM, Lars Brownies wrote: I have a person table and want to add an extra 1xM table: tblNotes. I'm doubting whether to add a specific primary key NotesID or to put a primary index over several fields: Solution 1: NotesID* PersonID DateTime_Entered UserID_Entered Note Solution 2: PersonID* DateTime_Entered* UserID_Entered* Note What would be best? Thanks, Lars You say 1xM. Therefore, it has to be solution 1. Solution 2 is more expensive for no good reason. Besides, if you really wanted to prevent duplicate of #2: CREATE TABLE Notes ( NotesID AUTOINCREMENT PRIMARY KEY, PersonID INT NOT NULL, DateTime_Entered DATETIME NOT NULL, UserID_Entered INT NOT NULL, CONSTRAINT fkPeopleNotes FOREIGN KEY(PersonID) REFERENCES People(PersonID), CONSTRAINT uniqueNote UNIQUE (PersonID, DateTime_Entered, UserID) ); This will give you the simplicity of #1 and prevention duplication equally well as #2 at expense of maintaining three indexes instead of two for either solution. Whether the expense is worth it, is a decision you need to consider. Personally I'm inclined to say #1 is good enough - it'd be exceedingly unlikely that a duplicate of { PersonID, DateTime_Entered, UserID } would actually occur. |
#4
| |||
| |||
|
|
I have a person table and want to add an extra 1xM table: tblNotes. I'm doubting whether to add a specific primary key NotesID or to put a primary index over several fields: Solution 1: NotesID* PersonID DateTime_Entered UserID_Entered Note Solution 2: PersonID* DateTime_Entered* UserID_Entered* Note What would be best? Thanks, Lars Normalization rules imply that you should not use a surrogate key |
#5
| |||
| |||
|
|
"Lars Brownies" <Lars (AT) Browniew (DOT) com> wrote in news:hsm6dj$peo$1 (AT) textnews (DOT) wanadoo.nl: I have a person table and want to add an extra 1xM table: tblNotes. I'm doubting whether to add a specific primary key NotesID or to put a primary index over several fields: Solution 1: NotesID* PersonID DateTime_Entered UserID_Entered Note Solution 2: PersonID* DateTime_Entered* UserID_Entered* Note What would be best? Thanks, Lars Normalization rules imply that you should not use a surrogate key when a natural key is available, because it wastes storage space. This means using solution 2 But rules were made to be broken. The surrogate rule is often broken to make database design simpler or execution faster. This means using solution 1 In your case, flipping a coin to choose the solution will save hours in deciding which structure to use. There was a thread, maybe 3 years ago, with a discussion on whether or |
#6
| |||
| |||
|
|
"Lars Brownies" <Lars (AT) Browniew (DOT) com> wrote in news:hsm6dj$peo$1 (AT) textnews (DOT) wanadoo.nl: I have a person table and want to add an extra 1xM table: tblNotes. I'm doubting whether to add a specific primary key NotesID or to put a primary index over several fields: Solution 1: NotesID* PersonID DateTime_Entered UserID_Entered Note Solution 2: PersonID* DateTime_Entered* UserID_Entered* Note What would be best? Thanks, Lars Normalization rules imply that you should not use a surrogate key when a natural key is available, because it wastes storage space. This means using solution 2 But rules were made to be broken. The surrogate rule is often broken to make database design simpler or execution faster. This means using solution 1 In your case, flipping a coin to choose the solution will save hours in deciding which structure to use. |
#7
| |||
| |||
|
|
Bob Quintal wrote: "Lars Brownies" <Lars (AT) Browniew (DOT) com> wrote in news:hsm6dj$peo$1 (AT) textnews (DOT) wanadoo.nl: I have a person table and want to add an extra 1xM table: tblNotes. I'm doubting whether to add a specific primary key NotesID or to put a primary index over several fields: Solution 1: NotesID* PersonID DateTime_Entered UserID_Entered Note Solution 2: PersonID* DateTime_Entered* UserID_Entered* Note What would be best? Thanks, Lars Normalization rules imply that you should not use a surrogate key when a natural key is available, because it wastes storage space. This means using solution 2 But rules were made to be broken. The surrogate rule is often broken to make database design simpler or execution faster. This means using solution 1 In your case, flipping a coin to choose the solution will save hours in deciding which structure to use. There was a thread, maybe 3 years ago, with a discussion on whether or not to use an autonumber field as a primary key or leave it off. Me, I like a primary key like an autonumber. It makes it easy to find records. Even if I don't need to find a record, I prefer having a primary key. Just habit. Some thought the use of an autonumber primary in some cases was unneeded. The bottom line aka result of the thread seemed to be "I'll do it the way I prefer". |
![]() |
| Thread Tools | |
| Display Modes | |
| |