我有以下观点(没有schyrsem的学生)显示SchYrSem表中没有相关记录的记录列表:
SELECT Students.IDNo, Students.LastName, Students.FirstName
FROM Students LEFT JOIN SchYrSem ON Students.[IDNo] = SchYrSem.[IDNo]
WHERE (((SchYrSem.IDNo) Is Null));
当我删除记录时,它说:
视图或函数'没有schyrsem的学生'不可更新,因为修改会影响多个基表。
任何想法如何从SchYrSem表中的匹配记录中删除学生表中的记录?
答案 0 :(得分:2)
DELETE s
FROM dbo.Students AS s
LEFT OUTER JOIN dbo.SchYrSem AS ss
ON ss.IDNo = s.IDNo
WHERE ss.IDNo IS NULL;
或者
DELETE s
FROM dbo.Students AS s
WHERE NOT EXISTS
(
SELECT 1
FROM dbo.SchYrSem
WHERE IDNo = s.IDNo
);
你不应该试图从视图中删除一行,恕我直言。