Click here to Skip to main content
13,090,730 members (44,058 online)
Rate this:
Please Sign up or sign in to vote.
See more:
hi guys,

i have a table in sql server like this

student_ID Course month mark

student get a mark in each month
i want if a june mark is in databse for particular student id then it not store again on it. But in july month data is store for same student with same Id.

but i dont want to store a mark on same month.

please help
Posted 11-Oct-12 10:56am
Updated 11-Oct-12 10:58am
Sergey Alexandrovich Kryukov 11-Oct-12 17:03pm
And how can it be a problem?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You need a unique constraint on the column combination of student_ID, Course and Month.
Member 8214635 11-Oct-12 17:18pm
if i use a student id as a primary key the it is not possible to add mark again on same ID but student id is not change after a month. so it is not possible to take a student id as a primary key. In month, also problem for primary key if i take a it as a primary key then other student marks for same month is stored. In course, same as month. it is not stored data for that course for other student.
Member 8214635 11-Oct-12 17:20pm
can i do that before store a data it will check whether a detail for same student id for specific month is entered or not
Marcus Kramer 11-Oct-12 17:45pm
Please reread my answer. I'm not talking at all about how you set up your primary key, but your primary key should NOT be the student ID, but would probably work best as an auto-increment IDENTITY. You need a UNIQUE constraint on the 3 columns together, the database will then throw an error if someone attempts an insert on the table with a duplicate set of student_ID, month and course.
damodara naidu betha 12-Oct-12 2:14am
Good one Marcus.. 5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100