Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Greatness
Starting Member
2 Posts |
Posted - 2012-10-31 : 08:37:37
|
Hello folks!My truly apologies if topic with same/similar problem like mine exist- I couldnt' find it. I am new to SQL server , actually I am new in database modeling and I stuck with I guess easy "problematique". I have table "MARKS" and in MARKS I have columns IDteacher , IDstudent, Month and Mark. Student cant be marked more than once in month. How to solve that? I guess that instead of insert trigger should check does student got mark in current month and announce error if row with same IDstudent and Month exist. I appricate any help and thanks very much in advance! |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-10-31 : 08:59:40
|
You should be able to add a unique constraint to your table indicating that no more than one row for a given combination of IDTeacher, IDStudent and Month can be inserted into the table. ALTER TABLE YourTableName ADD CONSTRAINT Unique_TeacherStudentMonth (IDteacher , IDstudent, [Month]); You may also want to add a year column if the data can span more than one year. |
 |
|
Greatness
Starting Member
2 Posts |
Posted - 2012-10-31 : 09:54:41
|
THANK YOU VERY MUCH! Worked like a charm. And thanks for advice for year column. Could you maybe recommend some good pdf book for sql server? |
 |
|
|
|
|