cascading-deletes

tsql script to add delete cascade to existing tables

泪湿孤枕 提交于 2019-12-04 01:46:52
is there a script that can be used to enable cascaded deletion for existing tables. Thanks. VMAtm ALTER TABLE [wm].[TABLE_NAME] WITH NOCHECK ADD CONSTRAINT [FK_TABLE_NAME_PARENT_TABLE_NAME] FOREIGN KEY([FOREIGN_KEY]) REFERENCES [wm].[PARENT_TABLE_NAME] ([PRIVATE_KEY]) ON DELETE CASCADE GO TABLE_NAME : name of the table where the children are stored. PARENT_TABLE_NAME : name of the table where the parents are stored. This placeholders can be equal FK_TABLE_NAME_PARENT_TABLE_NAME : just name for the constraint FOREIGN_KEY : field in the child table for the connection with the parents, for

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

谁说胖子不能爱 提交于 2019-12-03 07:53:45
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 example: Say, I delete node '11', I want node '2' to be deleted as well(and in my own example, they'll be nodes under 2 that will now have to be deleted as well) because its not connected to the main graph anymore. Note, that node '9' or '10' should not be deleted because node '8' and '3' connect to them still. I'm using the python library networkx. I searched

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

你离开我真会死。 提交于 2019-12-03 07:26:30
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 child) { children.Remove(child); } When I try to save the changes I get the following error: A relationship from the 'ParentChild' AssociationSet is in the 'Deleted' state. Given multiplicity constraints, a corresponding 'Child' must also in the 'Deleted' state. Surely I don't have to delete the child entity explicitly using a child repository! It

Entity framework one to zero or one relationship without navigation property

眉间皱痕 提交于 2019-12-02 14:29:45
问题 I hit an issue when trying to delete records due to FK constraints. I therefore went back to the drawing board and am trying to specify how the relationship should work. Here are my code first classes: public class MemberDataSet { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public int? DeferredDataId { get; set; } [ForeignKey("DeferredDataId")] public virtual DeferredData DeferredData { get; set; } } public class DeferredData { [Key]

Entity framework one to zero or one relationship without navigation property

爷,独闯天下 提交于 2019-12-02 03:22:05
I hit an issue when trying to delete records due to FK constraints. I therefore went back to the drawing board and am trying to specify how the relationship should work. Here are my code first classes: public class MemberDataSet { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public int? DeferredDataId { get; set; } [ForeignKey("DeferredDataId")] public virtual DeferredData DeferredData { get; set; } } public class DeferredData { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int Id { get; set; } //other properties

My 'ON DELETE CASCADE ' does not work

懵懂的女人 提交于 2019-12-02 03:08:27
I have got 3 tables: lt_hdefaults , lt_hperiods and lt_hrules . In lt_hdefaults , there is one row for a property for a particular year. In the lt_hperiods table, there could be more than one period, call them seasons. In the lt_hrules table, there could be more than one rule for each period. Now, what I could not make work: when the user deletes a record from lt_hdefaults , other data related to the deleted record should be removed from lt_hperiods and lt_hrules table. I am trying to achieve this by using FOREIGN KEY (lt_year,lt_id) REFERENCES lt_hdefaults(lt_year,lt_id) ON DELETE CASCADE

sql server, cascade delete and parent/child table

百般思念 提交于 2019-12-02 00:25:36
问题 i have one simple table with following columns: id, name and parentID i created relationship diagram between id and parentID (on a same table), like simple tree, on the same table, but when i tried to user cascade delete it was disabled for me i know that it will be recursive delete if i will delete parent it will delete his children have i any options for anable cascade delete without triggers? 回答1: No, SQL Server does not allow recursive and/or multiple cascade paths. You can use a stored

How to avoid database deadlocks?

依然范特西╮ 提交于 2019-12-01 07:34:14
Some database features, such as SELECT ... FOR UPDATE and ON DELETE CASCADE , are implicitly vulnerable to deadlocks because the database does not specify what locking order will be used. I found two discussions that hint that this behavior isn't specified by the SQL standard, not to mention specific implementations. As such, I'm operating under the assumption that we cannot control the locking order (at least, it's not obvious how to do so). How are we supposed to avoid database deadlocks if we cannot rely on the locking order? If we're not supposed to avoid deadlocks (you're going to have to

SQL Server 2008 - Multiple Cascading FK's - Do i need a trigger?

≯℡__Kan透↙ 提交于 2019-12-01 05:48:26
I have a 1..* relationship between User and Post . (one user has many posts) Post has a FK called "UserId", which maps to the "UserId" field on User table. I tried to set this FK as Cascade UPDATE/DELETE, but i get this error: 'Users' table saved successfully 'Posts' table - Unable to create relationship 'FK_Posts_Users'. Introducing FOREIGN KEY constraint 'FK_Posts_Users' on table 'Posts' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint. See previous errors. I have a table

How to avoid database deadlocks?

泄露秘密 提交于 2019-12-01 04:51:56
问题 Some database features, such as SELECT ... FOR UPDATE and ON DELETE CASCADE , are implicitly vulnerable to deadlocks because the database does not specify what locking order will be used. I found two discussions that hint that this behavior isn't specified by the SQL standard, not to mention specific implementations. As such, I'm operating under the assumption that we cannot control the locking order (at least, it's not obvious how to do so). How are we supposed to avoid database deadlocks if