且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除SQL Server中的记录

更新时间:2023-02-07 12:48:09

DELETE FROM Employee WHERE EmpID=10

除非仍然存在引用它的经理记录,否则将删除行。

To确定,首先删除经理记录:

Will delete teh row, unless there is still a manager record that refers to it.
To do sure, delete the manager records first:

DELETE FROM Manager WHERE EmpID = 10;
DELETE FROM Employee WHERE EmpID = 10;



为安全起见,您应在两个删除周围使用TRANSACTION以确保参照完整性。



您可以将Cascade Delete设置为on,但这有点危险:这意味着一个小错误会产生严重后果。


For safety, you should use a TRANSACTION around both deletes to ensure referential integrity.

You could set Cascade Delete to on, but that's a bit dangerous: it means a small mistake can have drastic consequences.