问题描述
员工表格如下
Empid PK
经理表格如下
MangerId
Empid Foriegn钥匙
Empname
经理列中的表格Empid Foriegn键指的是50个约束
在Empid列主键中的Employee表中。
i想要删除EMpid 10的记录
为什么在sql server中怎么办
我的尝试:
Employee table as follows
Empid PK
Manager table as follows
MangerId
Empid Foriegn key
Empname
In manager table in the column Empid Foriegn key refers 50 constraints
In Employee table in the Empid column Primary key.
i want to delete the record of EMpid 10
for that how to do in sql server
What I have tried:
Employee table as follows
Empid PK
Manager table as follows
MangerId
Empid Foriegn key
Empname
In manager table in the column Empid Foriegn key refers 50 constraints
In Employee table in the Empid column Primary key.
i want to delete the record of EMpid 10
for that how to do in sql server
推荐答案
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.
这篇关于删除SQL Server中的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!