Help Delete Query (1 Viewer)

GaDauBac

Member
Local time
Today, 22:16
Joined
Mar 22, 2021
Messages
42
I have 1 database (attachment)
- I can't run Delete query to manually delete specified fields
Please everyone help me. Thank you very much!
 

Attachments

  • Hoi.accdb
    3.2 MB · Views: 188

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:16
Joined
May 7, 2009
Messages
19,247
there is no attachment
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:16
Joined
May 7, 2009
Messages
19,247
check and test.
 

Attachments

  • Hoi.accdb
    3.3 MB · Views: 124

GaDauBac

Member
Local time
Today, 22:16
Joined
Mar 22, 2021
Messages
42

Attachments

  • Capture1.JPG
    Capture1.JPG
    32.4 KB · Views: 165

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:16
Joined
Feb 19, 2002
Messages
43,346
The schema is incorrect. It violates second normal form. MaKH does not belong in tb2_ChiTietHopDong. You would obtain the MaKH value by joining to tbl2_ThongTinHopDong.

You didn't explain what exactly your problem was but when you have two related tables in a query and you try to delete a row (you CANNOT delete a column, you only delete rows), it is the "child" table that you delete from NOT the parent table. If you want to delete a row from a parent table based on a value in the child table, you MUST have cascade delete specified since you obviously cannot delete a parent that has child record without it AND you need to use a sub query to identify the row since you can only delete child rows from a query with a join.
 

GaDauBac

Member
Local time
Today, 22:16
Joined
Mar 22, 2021
Messages
42
The schema is incorrect. It violates second normal form. MaKH does not belong in tb2_ChiTietHopDong. You would obtain the MaKH value by joining to tbl2_ThongTinHopDong.

You didn't explain what exactly your problem was but when you have two related tables in a query and you try to delete a row (you CANNOT delete a column, you only delete rows), it is the "child" table that you delete from NOT the parent table. If you want to delete a row from a parent table based on a value in the child table, you MUST have cascade delete specified since you obviously cannot delete a parent that has child record without it AND you need to use a sub query to identify the row since you can only delete child rows from a query with a join.
Thank you! I edited it again, but when I delete the record in tbl2_ThongTinHopDong, I still get an error. I'm still studying with you.
 

Attachments

  • Capture.JPG
    Capture.JPG
    25.6 KB · Views: 187

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:16
Joined
Feb 19, 2002
Messages
43,346
You didn't remove MaKH from the rightmost table but that isn't causing the problem. It is just a design flaw.

You have RI enforced so you CANNOT delete rows from the middle table if there are rows in the right side table unless you allow Cascade Delete.
 

Users who are viewing this thread

Top Bottom