I have two tables, Employee
and Address
. I want to delete all employees and their associated addresses in Address
table. Can we write a single query to do so?
For below query can we use CASCADE keyword?
DELETE FROM Employee
I have two tables, Employee
and Address
. I want to delete all employees and their associated addresses in Address
table. Can we write a single query to do so?
For below query can we use CASCADE keyword?
DELETE FROM Employee
If you don't have foreign keys, easyest way to do this is to use a CTE or a view
with MyCTE as ( select T1.ID asT1ID,T2.ID as T2ID from T1 join T2 on T1.id = T2.id)
Delete MyCTE where T1ID = ???
or
Create view MyView
as
select T1.ID asT1ID,T2.ID as T2ID from T1 join T2 on T1.id = T2.id
delete MyView where T1ID = ??