cascading-deletes

Trigger calls in cascade deleting

大憨熊 提交于 2019-11-29 01:08:14
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 work with cascade deleting. Does any version of MySQL exist where my trigger will work with cascade deleting? Or, maybe, there is another way to call Niel de Wet From http://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html Cascaded foreign key actions do not activate triggers In other words, you cannot use the trigger with cascaded deleting.

iPhone Core Data: Cascading delete across a many-to-one relationship

南楼画角 提交于 2019-11-28 21:12:28
问题 I have two classes A and B with a many-to-one relationship from A to B (multiple A objects may reference the same B). The question is, if the delete rule on the A side is Cascade, will B be deleted only when the last referencing A is deleted or will it be deleted the first time an associated A is deleted. The delete rule for the B side of the relationship is Nullify if that matters. Also, I read in the Core Data docs that the Optional flag matters in some cases. But it wasn't clear how the

What are the options for overriding Django's cascading delete behaviour?

大城市里の小女人 提交于 2019-11-28 16:57:27
Django models generally handle the ON DELETE CASCADE behaviour quite adequately (in a way that works on databases that don't support it natively.) However, I'm struggling to discover what is the best way to override this behaviour where it is not appropriate, in the following scenarios for example: ON DELETE RESTRICT (i.e. prevent deleting an object if it has child records) ON DELETE SET NULL (i.e. don't delete a child record, but set it's parent key to NULL instead to break the relationship) Update other related data when a record is deleted (e.g. deleting an uploaded image file) The

How to cascade delete over many to many table

蓝咒 提交于 2019-11-28 13:22:36
I have a 3 tables that look like this: (source: InsomniacGeek.com ) On the foreign keys I have set cascade deletes. Right now, when I delete a record in the Folder table, only the related record in the FolderItem is deleted. This is expected and correct. What I would to accomplish is when I delete a record in the Folder table, the corresponding records in the FolderItem and the Item table should be deleted. How do I solve this? By adding a trigger that deletes all instances of Item with the FolderID in question? Or is there any better solution? You need to decide what behavior you want exactly

How to use delete cascade on MySQL MyISAM storage engine?

无人久伴 提交于 2019-11-28 12:12:24
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 tables with equipment parent table. I need to delete data from equipment when the equipment is moved, but I need to delete data in all my tables equipment_child1 to equipment_child8. then I remenber I had used DELETE CASCADE in innoDB engine, but now I'm using MyISAM engina, is that a problem? Any help, will really clarify ... Yes. Simply you

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

你离开我真会死。 提交于 2019-11-28 10:16:34
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 Anamnesis Anamnesis { get; set; } . . . } public class Anamnesis { [Key, ForeignKey("Student")] public int AnamnesisId { get; set; } public virtual Student Student { get; set; } . . . } where, Student is the principal entity and Anamnesis it the entity that shares the PK. Now I'd like that the relationship created had a Delete Rule = CASCADE. Actually, the

Entity Framework on delete cascade

大兔子大兔子 提交于 2019-11-28 09:55:30
I have problem with deleting related rows in Entity Framework 4.1. I have tables with relations Book 1<--->* BookFormats I have set the on delete cascade: ALTER TABLE [dbo].[BookFormats] WITH CHECK ADD CONSTRAINT [FK_BookFormats_Book] FOREIGN KEY([BookID]) REFERENCES [dbo].[Book] ([BookID]) on delete cascade The EDMX property Then, I want to remove the all BokFormats items related to my Book object: var originalBook = m.db.Book.First(x => x.BookID == bookId); originalBook.BookFormats.Clear(); m.db.SaveChanges(); But, I get the error: The operation failed: The relationship could not be changed

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

匆匆过客 提交于 2019-11-28 08:44:44
问题 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 can perform delete in all child table. But join on 20-30 tables? Its too much. Please let me know is there any other solution to delete all this child rows if parent get deleted. 回答1: You can do with ON DELETE CASCADE . ALTER TABLE childTable ADD

CASCADE Delete in many-to-many self-reference table

大憨熊 提交于 2019-11-28 08:18:51
问题 Table DISPLAY_TAB below is a self-reference table that can contain both parent and child tabs. A parent tab can have multiple child tabs and a child tab can belong to multiple parents. I'd like to establish a CASCADE DELETE relationship between main table and relationship table DISPLAY_TAB_GROUPING so when either parent or child tab is deleted - relationship is automatically deleted as well (just relationship, not actual tab record). So I am creating a FOREIGN KEY constrain on DISPLAY_TAB

Cascade delete using Fluent API

僤鯓⒐⒋嵵緔 提交于 2019-11-28 00:24:59
I have two entities. Profile and ProfileImages . After fetching a Profile I want to delete ProfileImages through Profile without it just removing the reference to Profile (setting it to null ). How can this be done with fluent API and Cascading Delete? Do I set the HasRequired attribute or the CascadeDelete attribute? public class Profile { //other code here for entity public virtual ICollection<ProfileImage> ProfileImages { get; set; } } public class ProfileImage { // other code here left out [Index] public string ProfileRefId { get; set; } [ForeignKey("ProfileRefId")] public virtual Profile