SQL Keep Getting Error with on Update Cascade

why i have an error when i use on update cascade?

there is no ON UPDATE CASCADE in oracle.

you may want to look at deferrable constraints which defers the foreign key check until commit, update the parent, update the child and then commit.

ALTER TABLE affaire_cassation
ADD CONSTRAINT key_fk_num_p
FOREIGN KEY(num_aff_a)
REFERENCES affaire_appel(num_aff)
DEFERRABLE INITIALLY DEFERRED;

You may also look for DEFERRABLE INITIALLY IMMEDIATE where you can defer the constraints on demand when you need it.


use with ALTER SESSION SET CONSTRAINTS = DEFERRED;

SQL Keep getting error with ON UPDATE CASCADE

Oracle does not have "ON UPDATE CASCADE". You can manually emulate this behavior by using triggers

Syntax Error for ON UPDATE CASCADE ON DELETE CASCADE

Oracle does not support cascades on updates, only deletes. So this works fine:

create table Doctor(
SSN int not Null,
Doc_id int not Null,
Dept_id int not Null,
HireDate Date not Null,
foreign key(SSN) references Person(SSN) on delete cascade
);

See here.

This is generally not a big limitation because you shouldn't be changing primary key values anyway.

Also, don't store social security numbers as integers. They are really strings that happen to be digits. In the US, at least, they can have leading zeros.

ON UPDATE CASCADE Giving unexpected error

It looks like you're trying to use MySQL syntax with DB2, which is not valid. DB2 does not support CASCADE on an UPDATE (search for rule-clause on this page).

If you are indeed using DB2 (and I'm assuming you're using DB2 for Linux/Unix/Windows here), then this should be the correct syntax:

ALTER TABLE integ 
ADD CONSTRAINT foreign_key_name
FOREIGN KEY (planner)
REFERENCES g_secure(planner)
ON UPDATE RESTRICT;

Getting missing keyword error when using ON DELETE/UPDATE in CREATE TABLE

The answer is simple - in Oracle, there's no ON UPDATE clause so - remove it. You can leave ON DELETE (if it does something; if it is NO ACTION, you can omit it).

MariaDB ON UPDATE CASCADE CONSTRAINT not working as expected?

See the comment on this page:

https://mariadb.com/kb/en/foreign-keys/

If ON UPDATE CASCADE recurses to update the same table it has previously updated during the cascade, it acts like RESTRICT. This means that you cannot use self-referential ON UPDATE CASCADE operations. This is to prevent infinite loops resulting from cascaded updates.

In other words, ON UPDATE CASCADE does not work if it's a hierarchical-data kind of table.

SQL Server ON DELETE CASCADE Error

Most likely it's because you reference "Users" from two different tables - Buyer in Purchases and Merchant in Sale. The database probably doesn't realize that these two records are never the same - but it knows that it's the same table and therefore complains about a potential issue with cascading.

On delete cascade error - How can I solve it with trigger?

Their is many ways to solve your problem. I will present only two solutions:

1- The simpliest one: Changing your table Poll_Vote_Table into 2 table one for Questions, one for Answers.

2- Use trigger instead of delete/update. It's actually what you want, but please consider solution 1. Now the code to use trigger (for reference):

(I'll just illustrate for the Question part. For Answer, it's the same.)

First you will have to recreate your FK as follow (after delete) :

ALTER TABLE [dbo].[Poll_Vote_Table]  WITH CHECK 
ADD CONSTRAINT [FK_Vote_Question] FOREIGN KEY([PollQuestionId])
REFERENCES [dbo].[Poll_Question_Table] ([PollQuestionId])

Then you will need to create the triggers :

CREATE TRIGGER [DELETE_Question_Vote]
ON dbo.[Poll_Question_Table]
INSTEAD OF DELETE
AS
BEGIN
SET NOCOUNT ON;
DELETE FROM [Poll_Vote_Table] WHERE PollQuestionId IN (SELECT PollQuestionId FROM DELETED)
DELETE FROM [Poll_Question_Table] WHERE PollQuestionId IN (SELECT PollQuestionId FROM DELETED)
END
GO

The update part is usually of no use, so I won't write about it but it's basicly the same as DELETE.



Related Topics



Leave a reply



Submit