I have two tables in a SQL Server Database, StudentAttendance
and Attendance
with the following structure:
Attendance
- AttendanceID
- TimeTableID
- AttendanceDate
- UserName
StudentAttendance
- StudentAttendanceID
- AttendanceID
- StudentID
- IsPresent
I run the following query and it works:
TRUNCATE TABLE StudentAttendance
But the following query gives me an error:
TRUNCATE TABLE Attendance
Msg 4712, Level 16, State 1, Line 4 Cannot truncate table 'Attendance' because it is being referenced by a FOREIGN KEY constraint.
Why do I get the above error even though the Attendance
table is empty?