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
12
votes
3 answers

MySQL: Foreign key constraints that exceed max depth

I have MySQL Server 5.1.62 installed on production server. I am monitoring mysql server's error log file every day and suddenly I found below error in my error log file. InnoDB: Cannot delete/update rows with cascading foreign key constraints that…
Saharsh Shah
  • 28,687
  • 8
  • 48
  • 83
11
votes
1 answer

tsql script to add delete cascade to existing tables

is there a script that can be used to enable cascaded deletion for existing tables. Thanks.
mike
  • 113
  • 1
  • 1
  • 4
10
votes
7 answers

How to find if a referenced object can be deleted?

I have an object called "Customer" which will be used in the other tables as foreign keys. The problem is that I want to know if a "Customer" can be deleted (ie, it is not being referenced in any other tables). Is this possible with Nhibernate?
Jey Geethan
  • 2,235
  • 5
  • 33
  • 60
10
votes
1 answer

How to delete automatically all reference rows if parent row get deleted in mysql?

I have a database which contains around 50 tables. Suppose I have a table named parent with id primary key and 24 approx child tables with reference to this parent table. I haven't used on delete cascade. I have already searched about doing joins…
9
votes
3 answers

Java Spring cascade elementcollection delete

For some reason my delete is not cascading when I try to delete the parent element which has an elementcollection in it, the two classes are as follows: @Entity @Table(name="Timestamps") @JsonIgnoreProperties(ignoreUnknown = true) public class…
IDKWhatImDoing
  • 137
  • 1
  • 13
9
votes
2 answers

Relation table delete-cascade in 4 cases but Entity-config allows only 2

I have two normal tables and one relation table. -------------------------------------------------- | Group | Membership | User | | (ID, NAME) |(GRP_ID, U_ID) |(ID, FORENAME) | …
Grim
  • 1,938
  • 10
  • 56
  • 123
9
votes
1 answer

How to use delete cascade on MySQL MyISAM storage engine?

I have one table that I had called equipment, and 8 other tables that I had called equipment_child1 and so on until equipment_child8. The commom field between all that tables is cod_equip, with this field I 'm able to identify all my child equipment…
devasia2112
  • 5,844
  • 6
  • 36
  • 56
9
votes
3 answers

Delete parent if the child is deleted

I want to delete the parent row if the associated rows in child tables have been removed. class Child(Base): __tablename__ = "children" id = Column(Integer, primary_key=True) parent_id = Column(Integer, ForeignKey("parents.id",…
mad_
  • 8,121
  • 2
  • 25
  • 40
9
votes
3 answers

How do I delete a child entity from a parent collection with Entity Framework 4?

I'm using Entity Framework 4 and have a one-to-many relationship between a parent and child entity. I'm trying to delete a child using the parent repository by removing it from the parent's children collection: public virtual void RemoveChild(Child…
simonjreid
  • 195
  • 2
  • 7
9
votes
2 answers

Grails - multiple belongsTo of same class with cascading deletion

This one is for the Grails users here. I asked it on the grails - user mailing list, but I figured since I've been fighting this for a couple of days I should cast as wide a net as possible. I'm having some difficulty with trying to model…
Dave
9
votes
4 answers

Cascade deletion of embeddable objects' collection

I have an entity A that has a collection of basic types (e.g. String). I use such a mapping because the strings associated to each instance of A depend on A's lifecycle. If I want to remove an instance of A from the DB, I also want its associated…
manash
  • 6,985
  • 12
  • 65
  • 125
7
votes
2 answers

How to delete all related nodes in a directed graph using networkx?

I'm not sure exactly sure what the correct terminology is for my question so I'll just explain what I want to do. I have a directed graph and after I delete a node I want all independently related nodes to be removed as well. Here's an…
Lostsoul
  • 25,013
  • 48
  • 144
  • 239
7
votes
1 answer

Code first causing required relation to be optional?

public class Client { public Int32 ClientID { get; set; } public virtual ICollection InquiryManufacturers { get; set; } public virtual ICollection Products { get; set; } public virtual ICollection
user781310
  • 83
  • 1
  • 1
  • 7
7
votes
1 answer

NHibernate, "On Delete Cascade", cascade deleting rows in related tables?

I've been using NHibernate (with Fluent-NHibernate mappings) in a project for the first time over the last few weeks, all was going well until today when I've hit a problem (most probably my own error). I've made a small sample to illustrate what…
7
votes
2 answers

Cascade Delete Rule in EF 4.1 Code First when using Shared Primary Key Association

I implemented a bidirectional 1:1 relationship based on this answer: Primary /Foreign Key in Entity Framework I define the bidirectional relation this way: public class Student { public virtual int StudentId { get; set; } public virtual…