Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL Server
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
thanks
Posted 11-Oct-12 11:56am
Edited 11-Oct-12 11:58am
v2
Comments
Sergey Alexandrovich Kryukov at 11-Oct-12 17:03pm
   
And how can it be a problem?
--SA

1 solution

Rate this: bad
good
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.
  Permalink  
Comments
Member 8214635 at 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 at 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 at 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 at 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
0 Kornfeld Eliyahu Peter 169
1 Zoltán Zörgő 139
2 George Jonsson 135
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2014
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