Access won't let me delete rows because of key violations

Summoner226

New member
Local time
Yesterday, 17:31
Joined
Jul 27, 2024
Messages
2
I'm trying to delete records from a table (we'll call it table A) but it won't let me because of key violations. It will let me delete them in a copy of the table I made (using copy paste and a new name). The records in table A has a 1-many relationship with records in Table B which have a many to 1 relationship with records in table C. I am deciding which records in Table A to delete based off information in linked records in Table B and C but only deleting stuff from Table A. Is the error being caused by me not also deleting records from Tables B and C that match the records in table A, and if so is there a way to only delete stuff from Table A?

It say I'm using Access 2007 - 2016 file format. I have not used Access before not made these databases so I'm not sure what the differences are between a table and a copy paste of that table with a new name. Also if it helps when testing my delete query I made and used copies of Tables A B and C.
 
Is Referential Integrity enforced in table Relationships?
If you want to provide db for analysis, follow instructions at bottom of my post.
 
Last edited:
If Referential Integrity is enforced on the relationship, but Cascade Delete is not, then it makes sense you cannot delete parent rows that have linked child rows, or you would orphan child rows, and violate RI.
 
If you want to delete records you have to think carefully.

If table A is 1 to many with table B, and tableB is 1 to many with table C, then you can't delete a record from table A or B, if it would leave an orphan in the subsidiary table.

So you need to be careful if you allow cascade deleting, as you might find you delete some records you really didn't want to.
 
I'm trying to delete records from a table (we'll call it table A) but it won't let me because of key violations. It will let me delete them in a copy of the table I made (using copy paste and a new name). The records in table A has a 1-many relationship with records in Table B which have a many to 1 relationship with records in table C. I am deciding which records in Table A to delete based off information in linked records in Table B and C but only deleting stuff from Table A. Is the error being caused by me not also deleting records from Tables B and C that match the records in table A, and if so is there a way to only delete stuff from Table A?

It say I'm using Access 2007 - 2016 file format. I have not used Access before not made these databases so I'm not sure what the differences are between a table and a copy paste of that table with a new name. Also if it helps when testing my delete query I made and used copies of Tables A B and C.
The real question is why must you delete records? You can always mark records inactive and then filter them out of any queries, thus avoiding the deletions.

If there are other records that depend on the one's you are deleting, that will cause the error. On the original db, navigate to Database Tools > Relationships. Examine each of the tables connected to table A and you find there are probably records in those other tables that depend on records you attempting to delete. As already stated, there is the referential integrity being enforced, which is a good thing as you could have borked up the database by creating a bunch of orphaned records.

You could post the schema diagram of the tables here so we can look at it (Database Tools > Relationships).
 

Users who are viewing this thread

Back
Top Bottom