I have a database table as follows:
create table Table1(
Date varchar(10),
Batch_Name varchar(50),
Hall_Name varchar(50),
Lecturer_Name varchar(100))
I want to create a trigger for this table, which will restrict inserting the same Batch Name, Hall Name, OR Lecturer name on a particular day.
For example: if the user inserted,
**Record 1 :** 2012/08/15 - Batch 1 - Hall 1 - Lecturer 1
**Record 2 :** 2012/08/15 - Batch 2 - Hall 2 - Lecturer 2
to the table, it should be correct. But if the user tried to insert as
Record 1 : 2012/08/15 – Batch 1 – Hall 1 – Lecturer 1
**Record 2 :** 2012/08/15 - Batch 1 - Hall 1 - Lecturer 2 **OR**
**Record 2 :** 2012/08/15 - Batch 1 - Hall 2 - Lecturer 1 **OR**
**Record 2 :** 2012/08/15 - Batch 2 - Hall 1 - Lecturer 1
it should provide an error.
I am using this table to create a time table for a particular system. What I am trying to achieve by this trigger is that I want to provide an error if the user tries assign the same hall, lecturer or the Batch on the same day on different records, which obviously is an over allocation.
I am quite a newbie when it comes to triggers, so I would really appreciate if someone can provide me a solution for this scenario! and I am using MS SQL Server 2008 as the DBMS.
Thanks in advance!
i think this is not necessarily a trigger
this sounds like a set of 3 unique indexes.
create a unique index on the pairs: