这是 ms 创建表脚本:
SchoolclassCode 和 Pupil 表之间是 N:M 关系
CREATE TABLE Schoolclasscode (
schoolclassId integer PRIMARY KEY AUTOINCREMENT NOT NULL
);
CREATE TABLE SchoolclasscodePupil (
pupilId_FK integer NOT NULL,
schoolclassId_FK integer NOT NULL,
/* Foreign keys */
FOREIGN KEY (schoolclassId_FK)
REFERENCES Schoolclasscode(schoolclassId)
ON DELETE CASCADE
ON UPDATE NO ACTION,
FOREIGN KEY (pupilId_FK)
REFERENCES pupil(pupilId)
ON DELETE CASCADE
ON UPDATE NO ACTION
);
CREATE TABLE pupil (
pupilId integer PRIMARY KEY AUTOINCREMENT NOT NULL
);
当我在代码中删除 SchoolclassCode 对象时:
public void DeleteSchoolclass(int schoolclassCodeID, SQLiteConnection con)
{
using (SQLiteCommand com = new SQLiteCommand(con))
{
com.CommandText = "DELETE FROM schoolclasscode WHERE SchoolclassId = @SchoolclassId";
com.Parameters.Add(new SQLiteParameter("@SchoolclassId", schoolclassCodeID));
com.ExecuteNonQuery();
}
}
schoolclasscode 表中的条目被删除。但仅此而已。我什至可以另外删除 SchoolclasscodePupil 中的 schoolclasscodeId_FK 但没有学生被级联删除约束删除。
我错了什么?