Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
create table DeleteTest1
(
	EmpId int,
	Name nVarchar
	primary key (EmpId)
)



create table DeleteTest2
(
	EmpId int ,
	Age int,
	Salary Float
	constraint FK_TestDeleteEmpID Foreign key(EmpId)
	References DeleteTest1(EmpId)
)


insert into DeleteTest1  values (11614,'Vii')

insert into DeleteTest2 values (11614,21,12222)


delete dt2 from   DeleteTest1  dt1 inner join DeleteTest2 dt2 on dt2.EmpId=dt1.EmpId


What I have tried:

I tried deleting DeleteTest2 table first because it has foreign key reference, but i also want to delete DeleteTest1 table by joining both the tables.How can i delete these both table entries by a single join query
Posted
Updated 6-Mar-16 21:38pm

1 solution

 
Share this answer
 
v2
Comments
Maciej Los 7-Mar-16 4:22am    
Short and to the point, Peter!
Peter Leow 7-Mar-16 8:10am    
Thank you, Maciej.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900