Questions tagged [cascading-deletes]

The concept of SQL databases deleting rows that refer (via a foreign key) to a deleted row.

The concept of SQL databases deleting rows that refer (via a foreign key) to a deleted row. The deletion is performed recursively and enabled with the ON DELETE CASCADE property of the foreign key.

587 questions
2
votes
1 answer

Delete row from table:"Cannot delete or update a parent row:a foreign key constraint fails" is that a FOREIGN KEY problemm or CASCADE will do the job?

I want to delete a row from a "prods" table. Whenever I delete a row I want it to delete the rows from other tables associated with it. Whenever I try to delete a row from "prods" using my PHP code - I get this error: A Database Error…
Imnotapotato
  • 5,308
  • 13
  • 80
  • 147
2
votes
0 answers

JpaRepository deleteall() fails for elementcollection with FK constraint

I am using a JpaRepository for my ORM. @Entity @DiscriminatorValue(value = "L") @Table(name = "LARGEPROJECT") public class LargeProject extends Project { LargeProject() { // jpa only } public String description; @ElementCollection public…
2
votes
0 answers

How to improve many level dependant destroy performance

In my project there are many models with has_many association and dependant: :destroy flag. Also, each model have other belong_to associations with the dependant: :destroy flag. This models are nested between each other so when a destroy is executed…
2
votes
1 answer

How to count rows affected by cascade

Let's say I have two tables A and B. Table B has a foreign key that references Table A's primary key. And the foreign key has 'on delete cascade' constraint. And I am also using Java and JDBC to access this database. How do I know the number of rows…
alegro
  • 23
  • 3
2
votes
1 answer

LLBLGen Cascading Delete?

Is there any easy way to do what seems best described as a "Cascading Delete" in LLBLGen? An example of what I'm looking for: You've got these tables: Customer: -Id Order: -Id -CustomerId OrderDetail: -Id -OrderId Now, I want to delete a…
Fishtoaster
  • 1,809
  • 2
  • 20
  • 36
2
votes
1 answer

Hibernate all-delete-orphan on a child class with two parent classes

I'm looking into a problem, where there are two "parent" classes, P and Q that cascade all-delete-orphan to a "child" class, C. My intuition in Hibernate tells this is really a bad idea and I am getting an error message that probably confirms this…
Andy Hull
  • 1,843
  • 2
  • 14
  • 16
2
votes
1 answer

EntityFramework and cascading delete

I have an issue with cascading delete. I would like to use it if possible but in some cases it is not working for me. I have set up my DbContext to look like this: public class DatabaseContext : IdentityDbContext { // Define our tables …
r3plica
  • 13,017
  • 23
  • 128
  • 290
2
votes
0 answers

With an NHibernate EventListener can you determine if a cascade should occur?

I have two entities which have a one-to-one relationship. For the sake of consistency with other similar record types this relationship is maintained in a table with foreign key relationships to the corresponding entities. House ↔ Resident ↔…
ahsteele
  • 26,243
  • 28
  • 134
  • 248
2
votes
1 answer

See full effect of a cascading delete in MySQL workbench?

I have a MySQL database that is decently large and has various primary and foreign keys interconnecting everything. I'm trying to build up a spreadsheet of the effects of dropping various columns from various tables. I've imported the basic .sql…
Jedi Wolf
  • 331
  • 3
  • 13
2
votes
0 answers

Hibernate cascade delete multiple levels

Sorry for may English. I have 4 tables: **t1** id **t2** id t1_id **t3** id t2_id **t4** id t1_id t2_id In t2 entity I use it: @OneToMany(fetch=FetchType.LAZY, cascade = {CascadeType.ALL}, mappedBy="t2") Set
zerg
  • 255
  • 1
  • 3
  • 17
2
votes
1 answer

Delete an item from many-to-many relationship

I've following mapping for two tables having a Many-to-Many relationship between them. How do I delete an entry from the mapping table, which is 'TB_EMAIL_GRUPO_ARQUIVO' in my case? I just need to delete the data from this "joining" table and I…
2
votes
2 answers

MySQL, delete from multiple tables where id match and timestamp is older than current_time

Well, i have 4 tables, lets call them table1 table2 table3 and table4. In table1 i have a colum called "time" thats beeing updated with CURRENT_TIME on update´s. So i currently got this procedure to delete old stuff from the database: DELETE FROM…
Mordin
  • 47
  • 4
2
votes
2 answers

Nature of Lock is child table while deletion(sql server)

From couple of days i am thinking of a following scenario Consider I have 2 tables with parent child relationship of kind one-to-many. On removal of parent row i have to delete the rows in child those are related to parents. simple right? i have to…
Mubashar
  • 12,300
  • 11
  • 66
  • 95
2
votes
1 answer

Entity Framework cascading delete problems - Foreign key set to null

I have the following Model which I mapped with the Entity Framework: Mitglied -> Auftrag -> Teilprojekt I have set up everything in the database with foreign keys and "on delete cascade". If I perform some tests on the database everything works…
Manfred
  • 21
  • 1
  • 2
2
votes
1 answer

fluent-nhibernate cascade delete to collection of joined-subclassess

New user to fluent nhibernate here and I have a model with a parent class that holds a collection of subclassed children (using TablePerSubClass inheritance). When attempting to to test cascading deletes by calling delete only on the parent object I…