nikeloeleven
Programmer
Hi there. I'm new to Sql as you may know from my previous threads...I've been trying to Index a few of my tables.
I've searched everywhere but I havent been able to find out how to create an index on a table with more than one primary key i.e. joint primary keys.
Here is my small database structure:
Create Database 'c:\IPMBackbnone.Gdb' user 'SYSDBA' Password 'masterkey';
Create Table StaffMember
(StaffID VarChar(15) Not Null,
Forename VarChar(10) Not Null,
Surname VarChar(10) Not Null,
StaffGroup VarChar(10) Not Null,
Primary Key (StaffID)
);
Create Table FormTutor
(StaffID VarChar(15) Not Null,
Form VarChar(3) Not Null,
Primary Key (StaffID, Form),
Foreign Key (StaffID) References StaffMember(StaffID)
);
Create Table Pupil
(AdmissionNumber VarChar(4) Not Null,
Forename VarChar(10) Not Null,
Surname VarChar(10) Not Null,
DateofBirth VarChar(3) Not Null,
Form VarChar(3) Not Null,
Primary Key (AdmissionNumber),
Foreign Key (Form) References FormTutor(Form)
);
Create Table SubjectTarget
(AdmissionNumber VarChar(4) Not Null,
TargetNumber VarChar(15) Not Null,
TargetCategory VarChar(10) Not Null,
SubjectName VarChar(15) ,
Description VarChar(10) Not Null,
StrategyUsed VarChar(15) Not Null,
ExpectedEvidence VarChar(10) Not Null,
ReviewsMade VarChar(15) Not Null,
DateofLastReview VarChar(10) Not Null,
StatusofTarget VarChar(15) Not Null,
Evidence VarChar(10) Not Null,
Primary Key (AdmissionNumber, TargetNumber),
Foreign Key (AdmissionNumber) References Pupil(AdmissionNumber)
);
Create Table Subject
(SubjectName VarChar(15) Not Null,
StaffID VarChar(15) Not Null,
Primary Key (SubjectName),
Foreign Key (StaffID) References StaffMember(StaffID)
);
/* INDEXES FOR PRIMARY KEYS */
Create Unique Index StaffIDIndex On StaffMember(StaffID);
So far I've only created an Index on the StaffMember field. I want to create indexes on the other tables but some of them have more than one field as the primary key so I dont know how to index the tables with joint primary keys. Please can you help me on how to index them.
Some of the joint primary keys are also foreign keys so do i have "know anything specific" when i want to index joint keys where one or more of the fields are foreign keys?
Thanks a lot for ur help... I really appreciate it...
I've searched everywhere but I havent been able to find out how to create an index on a table with more than one primary key i.e. joint primary keys.
Here is my small database structure:
Create Database 'c:\IPMBackbnone.Gdb' user 'SYSDBA' Password 'masterkey';
Create Table StaffMember
(StaffID VarChar(15) Not Null,
Forename VarChar(10) Not Null,
Surname VarChar(10) Not Null,
StaffGroup VarChar(10) Not Null,
Primary Key (StaffID)
);
Create Table FormTutor
(StaffID VarChar(15) Not Null,
Form VarChar(3) Not Null,
Primary Key (StaffID, Form),
Foreign Key (StaffID) References StaffMember(StaffID)
);
Create Table Pupil
(AdmissionNumber VarChar(4) Not Null,
Forename VarChar(10) Not Null,
Surname VarChar(10) Not Null,
DateofBirth VarChar(3) Not Null,
Form VarChar(3) Not Null,
Primary Key (AdmissionNumber),
Foreign Key (Form) References FormTutor(Form)
);
Create Table SubjectTarget
(AdmissionNumber VarChar(4) Not Null,
TargetNumber VarChar(15) Not Null,
TargetCategory VarChar(10) Not Null,
SubjectName VarChar(15) ,
Description VarChar(10) Not Null,
StrategyUsed VarChar(15) Not Null,
ExpectedEvidence VarChar(10) Not Null,
ReviewsMade VarChar(15) Not Null,
DateofLastReview VarChar(10) Not Null,
StatusofTarget VarChar(15) Not Null,
Evidence VarChar(10) Not Null,
Primary Key (AdmissionNumber, TargetNumber),
Foreign Key (AdmissionNumber) References Pupil(AdmissionNumber)
);
Create Table Subject
(SubjectName VarChar(15) Not Null,
StaffID VarChar(15) Not Null,
Primary Key (SubjectName),
Foreign Key (StaffID) References StaffMember(StaffID)
);
/* INDEXES FOR PRIMARY KEYS */
Create Unique Index StaffIDIndex On StaffMember(StaffID);
So far I've only created an Index on the StaffMember field. I want to create indexes on the other tables but some of them have more than one field as the primary key so I dont know how to index the tables with joint primary keys. Please can you help me on how to index them.
Some of the joint primary keys are also foreign keys so do i have "know anything specific" when i want to index joint keys where one or more of the fields are foreign keys?
Thanks a lot for ur help... I really appreciate it...