Questions tagged [cascade]

Cascade refers to a table-definition keyword in relational databases; it instructs the query engine to take a certain action (delete, update), when a primary key is modified, on tables linked by a foreign key.

Cascade is a keyword that helps define the behavior of database tables linked by a foreign key, when the primary table is changed. If cascade is specified in the table definition, then, for example:

  • if a row in the primary table is deleted, the corresponding rows in the linked table can be deleted
  • if a primary key is updated, then the corresponding rows can be updated
1381 questions
304
votes
6 answers

What is the meaning of the CascadeType.ALL for a @ManyToOne JPA association

I think I misunderstood the meaning of cascading in the context of a @ManyToOne relationship. The case: public class User { @OneToMany(fetch = FetchType.EAGER) protected Set
userAddresses; } public class Address { …
forhas
  • 11,551
  • 21
  • 77
  • 111
241
votes
5 answers

How to add "on delete cascade" constraints?

In PostgreSQL 8 is it possible to add ON DELETE CASCADES to the both foreign keys in the following table without dropping the latter? # \d scores Table "public.scores" Column | Type |…
231
votes
8 answers

How does JPA orphanRemoval=true differ from the ON DELETE CASCADE DML clause

I am a little confused about the JPA 2.0 orphanRemoval attribute. I think I can see it is needed when I use my JPA provider's DB generation tools to create the underlying database DDL to have an ON DELETE CASCADE on the particular relation. However,…
Markos Fragkakis
  • 7,499
  • 18
  • 65
  • 103
173
votes
16 answers

When/Why to use Cascading in SQL Server?

When setting up foreign keys in SQL Server, under what circumstances should you have it cascade on delete or update, and what is the reasoning behind it? This probably applies to other databases as well. I'm looking most of all for concrete examples…
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
160
votes
3 answers

SQL ON DELETE CASCADE, Which Way Does the Deletion Occur?

If I have two relations in a database, like this: CREATE TABLE Courses ( CourseID int NOT NULL PRIMARY KEY, Course VARCHAR(63) NOT NULL UNIQUE, Code CHAR(4) NOT NULL UNIQUE ); CREATE TABLE BookCourses ( EntryID int NOT NULL PRIMARY KEY, …
Oliver Spryn
  • 16,871
  • 33
  • 101
  • 195
106
votes
1 answer

cascade={"remove"} VS orphanRemoval=true VS ondelete="CASCADE

I tried to gather some information about the following way to delete automatically child entity when a parent entity is deleted. Seems that the most common way is to use one those three annotation: cascade={"remove"} OR orphanRemoval=true OR…
Alexis_D
  • 1,908
  • 3
  • 16
  • 35
87
votes
4 answers

PostgreSQL: FOREIGN KEY/ON DELETE CASCADE

I have two tables like here: DROP TABLE IF EXISTS schemas.book; DROP TABLE IF EXISTS schemas.category; DROP SCHEMA IF EXISTS schemas; CREATE SCHEMA schemas; CREATE TABLE schemas.category ( id BIGSERIAL PRIMARY KEY, name …
juk
  • 2,179
  • 4
  • 19
  • 25
84
votes
1 answer

Doctrine: cascade="remove" vs orphanRemoval=true

What is the difference between the 2 options above? When is it preferable to choose each option?
iiirxs
  • 4,493
  • 2
  • 20
  • 35
84
votes
1 answer

Understanding Doctrine Cascade Operations

I want to check my understanding of cascade operations on Doctrine associations. For the purpose of this question, I have two models: Customer and Insuree. If I define a many to many relationship between a Customer and Insuree and set…
user2406944
67
votes
3 answers

MySQL RESTRICT and NO ACTION

What's the difference in a MySQL FK between RESTRICT and NO ACTION? From the doc they seem exactly the same. Is this the case? If so, why have both?
Erebus
  • 1,998
  • 2
  • 19
  • 32
67
votes
4 answers

JPA Hibernate many-to-many cascading

I am using JPA 2.0 and hibernate. I have a User class and a Group class as follows: public class User implements Serializable { @Id @Column(name="USER_ID") private String userId; @ManyToMany @JoinTable(name = "USER_GROUP", …
Hery
  • 7,443
  • 9
  • 36
  • 41
59
votes
5 answers

Haar Cascades vs. LBP Cascades in Face Detection

I have been experimenting with face detection in OpenCV (Open Source Computer Vision Library), and found that one could use Haar cascades to detect faces as there are several of them provided with OpenCV. However, I have noticed that there are also…
Bojoeb
  • 623
  • 1
  • 6
  • 6
52
votes
2 answers

TypeORM cascade option: cascade, onDelete, onUpdate

Do cascade options in TypeORM overlap or do they have a completely different purpose? Their description in the documentation is very scarce and partly missing, or I couldn't find it. IOW, do the following options { cascade: "update" } = { onUpdate:…
Serg
  • 6,742
  • 4
  • 36
  • 54
47
votes
3 answers

What is the difference between cascade & inverse in hibernate, what are they used for?

How to use cascade and inverse in hibernate? What is the procedure/tag to define them? Are they related to each other and how are they useful?
Chandra Sekhar
  • 16,256
  • 10
  • 67
  • 90
47
votes
2 answers

Should I use the CASCADE DELETE rule?

Duplicate of: When/Why to use Cascading in SQL Server? I've always been too scared to use DELETE CASCADE, but as I get more confident (lazy :D), I'm thinking how bad can it be, is it best practise to use it or should I avoid it and clean up my…
Ian G
  • 29,468
  • 21
  • 78
  • 92
1
2 3
91 92