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
44
votes
4 answers

How do I use on delete cascade in mysql?

I have a database of components. Each component is of a specific type. That means there is a many-to-one relationship between a component and a type. When I delete a type, I would like to delete all the components which has a foreign key of that…
Marius
  • 57,995
  • 32
  • 132
  • 151
42
votes
2 answers

Doctrine Cascade Options for OneToMany

I'm having a hard time making sense of the Doctrine manual's explanation of cascade operations and need someone to help me understand the options in terms of a simple ManyToOne relationship. In my application, I have a table/entity named Article…
cantera
  • 24,479
  • 25
  • 95
  • 138
39
votes
13 answers

In SQL Server 2005, can I do a cascade delete without setting the property on my tables?

I have a database full of customer data. It's so big that it's really cumbersome to operate on, and I'd rather just slim it down to 10% of the customers, which is plenty for development. I have an awful lot of tables and I don't want to alter them…
easeout
  • 8,665
  • 5
  • 43
  • 51
33
votes
7 answers

SQL Server: drop table cascade equivalent?

In oracle, to drop all tables and constraints you would type something like DROP TABLE myTable CASCADE CONSTRAINTS PURGE; and this would completely delete the tables and their dependencies. What's the SQL server equivalent??
Sinaesthetic
  • 11,426
  • 28
  • 107
  • 176
31
votes
4 answers

Trigger calls in cascade deleting

I have table "A" in MySQL. It has some references with cascade deleting to some other tables ("B", "C", "D" ...). I need to use a trigger when something deletes from "A". This trigger works when I delete records from "A" directly. But it doesn't…
user758690
  • 311
  • 1
  • 3
  • 3
31
votes
7 answers

Is it bad to rely on foreign key cascading?

The lead developer on a project I'm involved in says it's bad practice to rely on cascades to delete related rows. I don't see how this is bad, but I would like to know your thoughts on if/why it is.
Benbob
  • 13,876
  • 18
  • 79
  • 114
30
votes
1 answer

How do I create a Rails migration that updates a foreign key with an on-delete cascade constraint?

I’m using Rails 4.2.3 and a PostgreSQL database. I want to write a migration to update one of my foreign keys to have an on-delete cascade constraint, so I created the following: class UpdateForeignKeyAddOnDeleteConstraint <…
Dave
  • 15,639
  • 133
  • 442
  • 830
29
votes
2 answers

How to show related items using DeleteView in Django?

I am doing a view to delete (using the generic view DeleteView from Django) an instance from a model, but it cascades and deletes instances from other models: url(r'^person/(?P\d+)/delete/$', login_required(DeleteView.as_view(model=Person,…
staticdev
  • 2,950
  • 8
  • 42
  • 66
28
votes
5 answers

Hibernate: OneToMany save children by cascade

In the class Parent there is a list List. When the parent is saved the children which have been added or changed shall be save / updated by hibernate. I've found many explanations on this, however, I just don't get it to work. Parent.class try…
Steve Eastwood
  • 1,783
  • 3
  • 16
  • 21
28
votes
4 answers

How do the Postgres foreign key 'on update' and 'on delete' options work?

Can anyone provide a clear explanation / example of what these functions do, and when it's appropriate to use them?
meleyal
  • 32,252
  • 24
  • 73
  • 79
26
votes
4 answers

NHibernate Definitive Cascade application guide

Are there any internet resources that have a definitive guide to all of the cascade settings for NHibernate that will include examples of the class structure, HBM and the implications of actions with each of the cascade settings for all of the…
Chris Marisic
  • 32,487
  • 24
  • 164
  • 258
25
votes
6 answers

Detached entity passed to persist when save the child data

I'm getting this error when submitting the form: org.hibernate.PersistentObjectException: detached entity passed to persist: com.project.pmet.model.Account; nested exception is javax.persistence.PersistenceException:…
keysersoze
  • 2,562
  • 4
  • 21
  • 22
25
votes
1 answer

Nhibernate Cascade

What does Cascade in Nhibernate mean? I see a lot of options in cascading: Delete All AllDeleteOrphan DeleteOrphan SaveUpdate Can you explain these with with examples and their distinctions?
Quintin Par
  • 15,862
  • 27
  • 93
  • 146
24
votes
1 answer

What is the difference between REMOVE and DELETE?

Is there a difference between : @Cascade(org.hibernate.annotations.CascadeType.REMOVE) and @Cascade(org.hibernate.annotations.CascadeType.DELETE) ?
marhatta
24
votes
2 answers

MySQL on delete cascade. Test Example

I am wondering about this test question. I prepared the example myself and tested it but I still feel unsure of the answer. With the following: CREATE TABLE foo ( id INT PRIMARY KEY AUTO_INCREMENT, name INT ) CREATE TABLE foo2 ( id INT…
Eae
  • 4,191
  • 15
  • 55
  • 92
1
2
3
91 92