Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Samir H.
  Where is Samir H.?
 Yogyakarta
 Indonesia
 Samir H.
 To: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 Tags
Subject: RE: Composed Index as primary key?
Thread ID: 268913 Message ID: 268924 # Views: 29 # Ratings: 0
Version: Visual FoxPro 9 Category: Databases, Tables and SQL Server
Date: Thursday, July 15, 2010 1:21:52 PM         
   


I made a mistake and corrected it my original post. Here a copy:

#subj_notes.dbf structure#

ID (autoinc)
semester (int)
subject_id (int, relates to subjects.dbf)
student_id (int, relates to students.dbf)
comments (memo)
*below, indexes*
ID
#corrected composite index, I made a mistake#
wrong -> subj_stud (expression: STR(subject_id)+STR(student_id)
subj_stud (expression: STR(subject_id)+STR(student_id)+STR(semester)
subject_id && I not sure if this one is necessary...
student_id && I not sure if this one is necessary...
#end of subj_notes.dbf structure#


> subj_stud (expression: bintoc(subject_id)+bintoc(student_id)) && I am not sure you ever need this
Q1: Does this still apply? I mean your notes "I am not sure you ever need this"

> with 720 records I am not even sure that you need any indexes-a dream school:)
Unfortunately not a dream school. 70 Subj/competencies * xStudents * 12 semesters. Still not a huge amount, but it needs indexes.

> > Hi all
> > I have a file for teacher comments about school subjects, one record per subject/student/semester. The file is used for semester reports to parents.
> > If there are 10 students in the school, 6 subject matters and 12 semesters for the whole school period, then the table will have 720 records.
> >
> > The table looks like this:
> >

> > #subj_notes.dbf structure#
> >
> > ID (autoinc)
> > semester (int)
> > subject_id (int, relates to subjects.dbf)
> > student_id (int, relates to students.dbf)
> > comments (memo)
> > *below, indexes*
> > ID
> > subj_stud (expression: STR(subject_id)+STR(student_id)
> > subject_id && I not sure if this one is necessary...
> > student_id && I not sure if this one is necessary...
> > #end of subj_notes.dbf structure#

> >
> > Q: Can I make the composed index the primary key? It makes sense to me, but I want to ask first to make sure it's not against some rule I wouldn't know.
> > The records will always be accessed by that key. A seek() on "student_id" alone would not bring any meaningful result, since the user needs to know subject & semester too.
> >
> > Regards
> > Samir
>
> Can you make? Yes you can.
> Should you make? No you shouldn't.
>
> That would create another debate thread:)
>
> Everyone on its own but general best practices (well not written explicitly somewhere I think) tell that you should use a surrogate key as a primary key. It is there for you 'the developer' to uniquely identify a row in a table. It shouldn't be something that could be altered by end users. You have an autoinc column there generated on table and have no enduser interaction. Use it as a primary key (though my preference is a GUID on a canned local solution integer keys perfectly make sense).
> You can create another index either regular or candidate (if you would like it to have unique values enforced as in a primary key) for your composite key. Then maybe something like this:
>
> *below, indexes*
> ID
> subj_stud (expression: bintoc(subject_id)+bintoc(student_id)) && I am not sure you ever need this
> subject_id
> student_id
>
> with 720 records I am not even sure that you need any indexes-a dream school:)
>
> Cetin Basoz
>
> .Net has got better.Think about moving - check my blog:
> Blog (main)
> Blog (mirror)



Regards
Samir

ENTIRE THREAD

Composed Index as primary key? Posted by Samir H. @ 7/15/2010 11:26:26 AM
RE: Composed Index as primary key? Posted by Cetin Basoz @ 7/15/2010 12:34:34 PM
RE: Composed Index as primary key? Posted by Samir H. @ 7/15/2010 1:21:52 PM
RE: Composed Index as primary key? Posted by Cetin Basoz @ 7/15/2010 2:19:09 PM
RE: Composed Index as primary key? Posted by Samir H. @ 7/15/2010 2:40:10 PM
RE: Composed Index as primary key? Posted by Samir H. @ 7/15/2010 2:03:14 PM
RE: Composed Index as primary key? Posted by tushar @ 7/15/2010 2:16:13 PM
RE: Composed Index as primary key? Posted by Samir H. @ 7/15/2010 2:38:39 PM
RE: Composed Index as primary key? Posted by tushar @ 7/15/2010 3:44:03 PM
RE: Composed Index as primary key? Posted by Cetin Basoz @ 7/15/2010 2:35:00 PM
RE: Composed Index as primary key? Posted by Samir H. @ 7/15/2010 2:49:40 PM
RE: Composed Index as primary key? Posted by Cetin Basoz @ 7/15/2010 3:45:23 PM
RE: Composed Index as primary key? Posted by Samir H. @ 7/15/2010 4:01:37 PM
RE: Composed Index as primary key? Posted by Mike Yearwood @ 7/15/2010 8:21:47 PM
RE: Composed Index as primary key? Posted by Samir H. @ 7/16/2010 4:48:41 AM
RE: Composed Index as primary key? Posted by Mike Yearwood @ 7/16/2010 6:07:24 AM
RE: Composed Index as primary key? Posted by Samir H. @ 7/16/2010 6:16:14 AM
RE: Composed Index as primary key? Posted by Cetin Basoz @ 7/16/2010 1:12:42 PM
RE: Composed Index as primary key? Posted by Samir H. @ 7/16/2010 1:23:51 PM
RE: Composed Index as primary key? Posted by Samir H. @ 7/16/2010 1:46:54 PM
RE: Composed Index as primary key? Posted by tushar @ 7/15/2010 4:02:29 PM
RE: Composed Index as primary key? Posted by Samir H. @ 7/15/2010 4:12:41 PM
RE: Composed Index as primary key? Posted by Anders Altberg @ 7/16/2010 1:20:32 PM
RE: Composed Index as primary key? Posted by Samir H. @ 7/16/2010 1:31:56 PM