I have two tables, One is Contact and another is attendance table. For both
table, structures are as follow:
Contact
---------
Contactid smallint (Primary Key)
name varchar(20)
Attendance
-----------
AttendeeID Smallint
AttendeeType char(1)
AttendeeYear char(4)
I set the following constraint:
ALTER TABLE Attendance ADD
CONSTRAINT FK_ContactAttendance FOREIGN KEY
(AttendeeID) REFERENCES dbo.Contacts(ContactId)
On UPDATE CASCADE
On DELETE NO ACTION,
Constraint CK_Attendees Check (AttendeeType='O') or (AttendeeType='C')
Then I tried to test the above constraint for delete any contact for which
attendance is exist, it gives me following error:
Error Type:
Microsoft OLE DB Provider for SQL Server (0x80040E2F)
DELETE statement conflicted with COLUMN REFERENCE constraint
'FK_ContactAttendance'.
The conflict occurred in database 'Employee', table 'Attendance', column
'AttendeeID'.
I dont understand the problem, what wrong I am doing?
If someone help me in this matter, I will be thankful.