cascading-deletes

Deleting from two h2 tables with a foreign key

我与影子孤独终老i 提交于 2019-12-12 18:54:04
问题 I have an h2 database with two tables with foreign keys like CREATE TABLE master (masterId INT PRIMARY KEY, slaveId INT); CREATE TABLE slave (slaveId INT PRIMARY KEY, something INT, CONSTRAINT fk FOREIGN KEY (slaveId) REFERENCES master(slaveId)); and need something like DELETE master, slave FROM master m JOIN slave s ON m.slaveId = s.slaveId WHERE something = 43; i.e., delete from both tables (which AFAIK works in MySql). Because of the FOREIGN KEY I can't delete from the master first. When I

Which way around do cascading deletes go in a one-to-many relationship?

血红的双手。 提交于 2019-12-12 09:33:27
问题 Using Entity Framework code-first approach. Suppose I have two entity classes: [Table("Objects")] public class DbObject : IValidatableObject { public long Id { get; set; } public string Name { get; set; } public string Description { get; set; } public virtual ICollection<DbObjectProperty> Properties { get; set; } } [Table("ObjectProperties")] public class DbObjectProperty { public long Id { get; set; } public string Name { get; set; } public string Value { get; set; } [Display(Name = "Object"

ALTER TABLE to add ON DELETE CASCADE statement

落爺英雄遲暮 提交于 2019-12-11 18:48:45
问题 I want to do the following in PostgreSQL (using Hibernate): ALTER TABLE fruits ADD CONSTRAINTS id ON DELETE CASCADE; Obviously, my code above is not working, so I am looking for the correct statement. If I can't do that, then how about the following: I have a bunch of data in my table fruits . The id field in fruits is used as a foreign key by table grapes . I need to delete a specific row in fruits and I want the deletion to cascade to grapes and delete all entries in grapes that has the

MySQL Multi-Delete. Is it possible to multi-delete referenced rows?

守給你的承諾、 提交于 2019-12-11 10:34:55
问题 If I have a parent table and a child table, is it possible to multi-delete the rows in them without having a "ON DELETE CASCADE" constraint? In this example: create table a(id int primary key); create table b(id int primary key, a_id int, constraint fkb foreign key (a_id) references a(id)); Is it not possible to do something like this in order to delete rows in tables a and b? :-( delete a, b from b inner join a on a.id = b.a_id where a.id = ?; Error Code: 1451. Cannot delete or update a

How to set cascade on SQLite database with compound primary foreign key?

荒凉一梦 提交于 2019-12-11 10:16:35
问题 I have a db that's structured with a supertype table as well as subtype tables like so: EVENT PatientId INTEGER, DateTime TEXT, EventTypeCode TEXT, PRIMARY KEY( PatientId, DateTime, EventTypeCode ) different types of events have their own tables and have the same primary key, except that it's foreign. EXERCISE PatientId INTEGER, DateTime TEXT, EventTypeCode TEXT, PRIMARY KEY( PatientId, DateTime, EventTypeCode ) ON CONFLICT IGNORE, CONSTRAINT "PrimaryKey" FOREIGN KEY ("PatientId",

Manually call cascade delete?

☆樱花仙子☆ 提交于 2019-12-11 06:25:14
问题 Let's say I have 3 tables, "child1", "child2" and "child3", that all have a foreign key to the table "parent". Table "parent" got a field "status", and I would that if status is set to "0" for an element, all its child are deleted. (I use trigger to detect status changes). So it's like calling "cascade delete", but without deleting the object ... Is there a good way to do this ? 回答1: Trigger detects the change, you need to use it to fire a stored procedure. Here's a good tutorial: http:/

Delete an item from many-to-many relationship

半城伤御伤魂 提交于 2019-12-10 11:32:45
问题 I've following mapping for two tables having a Many-to-Many relationship between them. How do I delete an entry from the mapping table, which is 'TB_EMAIL_GRUPO_ARQUIVO' in my case? I just need to delete the data from this "joining" table and I don´t need to delete it from the "parent tables". GrupoModulo public GrupoModuloMap() { Schema(Const.SCHEMA); Table(Const.TB_EMAIL_GRUPO_MODULO); CompositeId() .KeyReference(x => x.Grupo, Const.ID_GRUPO) .KeyReference(x => x.Modulo, Const.ID_MODULO);

Grails belongsTo cascade on delete when belongsTo specifies multiple classes?

放肆的年华 提交于 2019-12-10 10:03:25
问题 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 O and S, what happens to O when S gets deleted? Would O still have D? Since it's a cascade-delete, both S and D would get deleted, right? When what happens to O? Would it still have D? 回答1: I have tested it, it follows the cascade rule: if you delete Owner, Dog

Cascade deleting from join table with @ManyToMany annotation

筅森魡賤 提交于 2019-12-07 12:14:53
问题 Hi I got a problem with mapping my entities. I'm using JPA2 and Hibernate implementation. I got tables with @ManyToMany annotation http://img204.imageshack.us/img204/7558/przykladd.png I mapped it with : @Entity @Table("employee") class Employee { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; @Column private String name; @ManyToMany @JoinTable(name = "proj_emp", joinColumns = @JoinColumn(name = "employee_id", referencedColumnName = "id"), inverseJoinColumns =

Entity Framework Cascade Delete For Inherited class

大城市里の小女人 提交于 2019-12-07 09:59:26
问题 Apparently Cascade Deleting with Entity Framework is very confusing. I found lot's of questions but I have not found a solution for my problem. If I manually set the "Delete Rule" to cascade it all works. But via Fluent API I haven't found a way to set this property in the database. In my case I have a base class (with it's own table in the database) public abstract class PropertyBase { public int PropertyID { get; set; } public string Name { get; set; } public virtual AspectBase AspectBase {