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
  • 305,152
  • 44
  • 369
  • 561
Karan Gandhi
  • 1,494
  • 2
  • 12
  • 20

3 Answers3

6

One of

Community
  • 1
  • 1
gbn
  • 422,506
  • 82
  • 585
  • 676
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
  • 305,152
  • 44
  • 369
  • 561
0

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

Andrew
  • 2,315
  • 3
  • 27
  • 42