更新时间:2023-02-03 07:40:57
您可以轻松地从表2中删除,但是如果要从表1中删除
使用
从table1级联删除
you can easily delete from table 2 but if you want to delete from table 1
use
delete from table1 cascade
如果要从table2中删除.要么
1.您应该从表1中删除所有相应的条目,然后只有u可以从表2中删除,否则它将显示
''DELETE语句与REFERENCE约束冲突''
2.如果您从表1中删除外键约束,则还有1个选项,那么您还可以从表2中删除行..
从表1的WHERE ID = 1
删除 GO
从table2中删除WHERE Emp_ID = 1
还有1种方法->否则在表定义中使用ON DELETE CASCADE.
If you want to delete from table2. either
1. You should to delete all the corresponding entries from table1, then only u can delete from table2,Or else it''ll show
''The DELETE statement conflicted with the REFERENCE constraint''
2. 1 more option is there if u drop the constraint of foreign key from table1, then also u can delete rows from table 2..
DELETE FROM table1 WHERE Id=1
GO
DELETE FROM table2 WHERE Emp_ID=1
1 more method -->Or Else use ON DELETE CASCADE with table Definition.
您好....
只要试试这个
ALTER TABLE table2
添加约束FK_table2ID外键(ID)
参考table1(id)
删除级联
祝你好运...
Hi there....
just try this one
ALTER TABLE table2
ADD CONSTRAINT FK_table2ID FOREIGN KEY (ID)
REFERENCES table1(id)
ON DELETE CASCADE
best of luck....