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
3
votes
1 answer

Postgres: Ignore DELETE triggers for cascade deletes

I am trying to implement a relation of persons to email addresses where a person must have at least one email address at all times. The tables look like this: CREATE TABLE persons ( id serial PRIMARY KEY, name text NOT NULL ); CREATE TABLE…
kcstricks
  • 1,489
  • 3
  • 17
  • 32
3
votes
2 answers

How to add cascade delete in oracle when the foreign key is on the same table

I have a table that contains a tree in oracle. MY_TABLE node_id parent_id How do I add a cascade delete when the root of the tree is not going to have a parent? Right now the parent id is set to -1 for the root. When I try this I get the following…
testing123
  • 11,367
  • 10
  • 47
  • 61
3
votes
1 answer

Grails belongsTo cascade on delete when belongsTo specifies multiple classes?

class Owner { static hasMany = Dog } class Sitter { static hasMany = Dog } class Dog { static belongsTo = [Owner, Sitter] } My question is: If I create a Dog instance D, a Owner instance O, a Sitter instance S and associate D with both…
Paul
  • 2,115
  • 3
  • 17
  • 14
3
votes
2 answers

NHibernate cascade delete

Let me begin with showing the mapping: Parent:
Bert Persyn
  • 401
  • 4
  • 13
3
votes
1 answer

Rails: Delete User without losing associations (or other methods of letting Users leave)

I have a Rails application that lets Users create various "judgements", everything is a bit interweaved, we have several classes that are connected to the User class. When I let users "destroy" their account, obviously the associations they had will…
slhck
  • 36,575
  • 28
  • 148
  • 201
3
votes
1 answer

Cascade delete related nodes using GraphQL and Prisma

I'm trying to figure out cascade deletion in GraphQL. I'm attempting to delete a node of type Question, but type QuestionVote has a required relation to Question. I'm looking for a way to delete a Question and all its votes at once. Mutation for…
Sam Hollon
  • 43
  • 1
  • 5
3
votes
2 answers

Cascade deletes on linked table joining 2 tables that each have a cascade delete to another table. How?

Let's assume the following objects as tables in SQL: Companies Employees (refers to companies) Meetings (also refers to companies) And employees can be in meetings so we have a link table: EmployeeMeetings (i.e. FK to both employees and…
3
votes
1 answer

SQL: Delete parent when child (but is theoretical parent) is deleted in a OneToOne relationship

Hello dear Stack Overflow community, I searched many hours already but I couldn't find a solution my quite unique scenario. Maybe you guys can help. Let's assume we have two tables. |domain_realm | | password_policy …
3
votes
2 answers

SQL Create Trigger Before Delete vs. Foreign Key On Delete

I have one table referencing another. As I see - there are two ways to delete cascading: What is the difference between CREATE TRIGGER BEFORE DELETE and FOREIGN KEY ON DELETE? Are there any differences in performance? I came up with this advantage…
SUhrmann
  • 632
  • 1
  • 8
  • 26
3
votes
1 answer

How do I cascade deletes into a link table using the EF4 fluent API?

I have two tables in an existing (MSSQL 2008 R2) database that are related by a link table. The two tables are "Plan" and "Tips". The link table is "PlanTipLinks". Plans can have many tips, and tips can be associated with multiple plans (i.e. it's a…
3
votes
1 answer

How to guard data structure consistency when calling external logic via observers?

I am currently refactoring an application in which classes can call observers if their state changes. This means that observers are called whenever: the data in an instance the class changes new instances of the class are created instances of the…
3
votes
1 answer

SQL Output on Cascaded Delete

Is it possible to output values from a cascaded delete in SQL? Something like: DELETE [Families] OUTPUT [deleted].[FamilyID] [deleted].[FamilyName], [Members].[MemberName] FROM [Families] LEFT JOIN [Members] ON…
Anton
  • 4,554
  • 2
  • 37
  • 60
3
votes
1 answer

cakephp 3.x cascade delete not working

I have 3 tables names articles,comments,addresses. articles -> fields(id,title,body) comments -> fields(id,article_id,comment) addresses-> fields(id,article_id,address) and in my articles controller i have kept dependent=>true and also…
Pavithra
  • 39
  • 4
3
votes
1 answer

Symfony: how to cascade undelete when using SoftDeleteable behavior extension?

My entity User is related to other entities through OneToOne relations, and I'm cascading "delete" for all of them. I'm using SoftDeleteable behavior extension, so when I remove a User, the entity is not actually removed from the database: the…
Roubi
  • 1,989
  • 1
  • 27
  • 36
3
votes
3 answers

Cascade deletion of database record to deletion of associated image file

I recently discovered the wonders of foreign keys and deletion cascading with InnoDB and I love it. It helps me easily delete intricate data structures without worrying about leaving junk behind. I'm currently storing images for a products database…
beeb
  • 1,187
  • 11
  • 32