Cascade

SQL Server: Self-reference FK, trigger instead of ON DELETE CASCADE

断了今生、忘了曾经 提交于 2019-11-27 07:59:26
问题 I need to perform an ON DELETE CASCADE on my table named CATEGORY, which has the following columls CAT_ID (BIGINT) NAME (VARCHAR) PARENT_CAT_ID (BIGINT) PARENT_CAT_ID is a FK on CAT_ID. Obviously, the lovely SQL Server does not let me use ON DELETE CASCADE claiming circular or multiple paths to deletion. A solution that I see often proposed is triggers. I made the following trigger: USE [ma] GO /****** Object: Trigger [dbo].[TRG_DELETE_CHILD_CATEGORIES] Script Date: 11/23/2009 16:47:59 ******

What are the Pros and Cons of Cascading delete and updates?

廉价感情. 提交于 2019-11-27 07:44:53
问题 Maybe this is sort of a naive question...but I think that we should always have cascading deletes and updates. But I wanted to know are there problems with it and when should we should not do it? I really can't think of a case right now where you would not want to do an cascade delete but I am sure there is one...but what about updates should they be done always? So can anyone please list out the pros and cons of cascading deletes and updates ? Thanks. 回答1: Pros: When you delete a row from

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

て烟熏妆下的殇ゞ 提交于 2019-11-27 06:13:10
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, BookID int NOT NULL, Course CHAR(4) NOT NULL, CourseNum CHAR(3) NOT NULL, CourseSec CHAR(1) NOT NULL ); and I establish a foreign key relationship between the two, like this: ALTER TABLE BookCourses ADD FOREIGN KEY (Course) REFERENCES Courses(Code) ON DELETE CASCADE; Then you can see that the Course attribute in the BookCourses relation references the Code

Hibernate : CascadeType.PERSIST does not work but CascadeType.ALL to save object

 ̄綄美尐妖づ 提交于 2019-11-27 06:05:59
问题 @Entity @Table(name = "Section_INST") public class Section { @javax.persistence.Id @GeneratedValue(strategy = GenerationType.SEQUENCE,generator = "Section_ID_GENERATOR") @SequenceGenerator(name = "Section_ID_GENERATOR",sequenceName = "Section_ID_SEQUENCER" , initialValue = 1 , allocationSize = 1) @Column(name = "Section_ID") private int Id; @Column(name = "Section_Name") private String name; @OneToOne(optional = false,cascade = CascadeType.PERSIST) @JoinColumn(name = "Exch_ID") private

SQL Server: drop table cascade equivalent?

狂风中的少年 提交于 2019-11-27 04:37:13
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?? I don't believe SQL has a similarly elegant solution. You have to drop any related constraints first before you can drop the table. Fortunately, this is all stored in the information schema and you can access that to get your whack list. This blog post should be able to get you what you need: http://weblogs.asp.net/jgalloway/archive/2006/04/12/442616.aspx -- t-sql

MySQL RESTRICT and NO ACTION

北慕城南 提交于 2019-11-27 02:01:40
问题 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? 回答1: From MySQL Documentation: https://dev.mysql.com/doc/refman/8.0/en/create-table-foreign-keys.html Some database systems have deferred checks, and NO ACTION is a deferred check. In MySQL, foreign key constraints are checked immediately, so NO ACTION is the same as RESTRICT . 回答2: They are identical in MySQL. In the SQL 2003 standard there are

how to define an inverse cascade delete on a many-to-one mapping in hibernate

陌路散爱 提交于 2019-11-27 01:56:05
问题 I have two classes A and B. Many B's can have association with a single A, hence a many-to-one relationship from B to A. I've mapped the relationship like: <class name="A" table="tbl_A"> <property name="propA" column="colA"/> </class> <class name="B" table="tbl_B"> <property name="propB" column="colB"/> <many-to-one name="a" class="A" column="col1" cascade="delete"/> </class> A has nothing mapped to B. Keeping this in mind we intend to delete B when it's associated A is deleted. This could

How to add “on delete cascade” constraints?

柔情痞子 提交于 2019-11-26 21:40:21
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 | Modifiers ---------+-----------------------+----------- id | character varying(32) | gid | integer | money | integer | not null quit | boolean | last_ip | inet | Foreign-key constraints: "scores_gid_fkey" FOREIGN KEY (gid) REFERENCES games(gid) "scores_id_fkey" FOREIGN KEY (id) REFERENCES users(id) Both referenced tables are below - here: # \d games Table "public.games" Column | Type | Modifiers ----------+------

Detached entity passed to persist when save the child data

烂漫一生 提交于 2019-11-26 20:38:36
问题 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: org.hibernate.PersistentObjectException: detached entity passed to persist: com.project.pmet.model.Account Here are my entities: Account: @Entity @DynamicInsert @DynamicUpdate public class Account { @Id @GeneratedValue private Integer id; @Column(nullable = false) private String

Understanding Doctrine Cascade Operations

*爱你&永不变心* 提交于 2019-11-26 18:59:12
问题 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 cascade{"all"} , I understand that this will: Adding a new insuree to a customer will persist this insuree and create an association in the join table. Removing an insuree from the collection will detach the insuree from the customer and detach the customer