471,071 Members | 5,747 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

Violation of primay key

Hi I am a first time user of sql server, and of late I am trying to build a database using sql server and I am starting to panic.

This is what I am trying to do: I am creating a db to register incoming students into a course.

1. I have two tables. Table A has all the fields for the student personal information in which I have Record # as the primary key. Table B has fields for the incoming student Educational Background (high school subject past) which has a Record # as the primary key.

2. I created a form using Table A and a subform using Table B which is linked via the Record #.

3. I am able to enter student personal information and one educational background information for a student, for example the school they attended, the year, subject pass and the grade.

However a student can have grades for more than one subject and there is where my problem is. The subform is continuous form since one student can have many subject past. When I enter information for a second subject for the same student in the subform I get " violation of primary key constraint 'PK_Education' Can not insert duplicate key in object 'Education' ".

How can I solve this problem?

What do I need to do or undo?

As I said before I am new to sql server and any help will be nice.

Thanks very very much.
Feb 18 '07 #1
1 1392
168 Expert 100+
You didn't partitioned your data correctly. As I understood you have:
1. Students
2. Subjects
3. Student grades on specific subjects.

Than you have to create three tables:
1. Student (StudentID, Name, ...) - will contain information about all students
2. Subjects (SubjectID, Name, ...) - will contain information about all subjects
3. Education (StudentID, SubjectID, Grade, DatePassed, ...) - will contain information about subjects passed by students.

This is a simple many-to-many relationship. It means that several students can pass a single subject, as well as one student can pass several subjects. This logic is accomplished using third table that handles relationship between Students and Subjects.
Feb 19 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

15 posts views Thread by Steven Reddie | last post: by
reply views Thread by Steven Reddie | last post: by
6 posts views Thread by J Smith | last post: by
reply views Thread by Microsoft News | last post: by
5 posts views Thread by Vayse | last post: by
7 posts views Thread by Kai-Uwe Bux | last post: by
39 posts views Thread by Martin | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.