3

I have 6 tables named A,B,C,D,E,F

I have A's Primary key, Now B have ref in A, C has ref in B, D has ref in C

E has ref in A, F has ref in B

Now I want to delete A's records and its related records in other tables and I have only A's primary key,

Best way to delete all records.

Thanks in advance.

duffymo
  • 299,921
  • 44
  • 364
  • 552
Karan Gandhi
  • 1,474
  • 2
  • 12
  • 20

3 Answers3

6

One of

Community
  • 1
  • 1
gbn
  • 408,740
  • 77
  • 567
  • 659
1

Delete the rows in the child tables by SELECTing their foreign key equal to A's primary key, then delete from A using the primary key.

duffymo
  • 299,921
  • 44
  • 364
  • 552
0

If its SQL Server you can set cascade delete to remove related records.

Andrew
  • 2,235
  • 3
  • 25
  • 41