Reputation: 1045
i am fresh to sql developer. i am not sure about the rules. when i practiced following teacher's example to create a small library database, i have that error to every table with foreign key. i check the example and i am sure i have not miss a parenthesis. i am so confused. please help!
create table Publisher
(Pname VARCHAR(25) not null ,
Address varchar(25) not null,
Phone char(10),
PRIMARY KEY (Pname));
create table Book
(Book_id int not null,
Title varchar(20),
Publisher_name varchar(25) ,
primary KEY (Book_id),
foreign key (Publisher_name) references Publisher(Pname)
ON DELETE CASCADE ON UPDATE CASCADE);
error report shows that between first cascade and second on "missing right parenthesis". but i don't think so. similar question happens to all other similar construct. my sql developer is the latest version for mac.
Upvotes: 0
Views: 477
Reputation: 881103
I assume you're trying to ensure that the Book
records are updated whenever you change the Pname
column in the Publisher
table, but Oracle has no on update cascade
.
See here for the syntax diagram of the references
clause.
To change primary keys in Oracle, you have a few options:
Defer the constraint (foreign key) check until commit, then update both parent and child within the transaction.
Create a new parent with the updated details then go change all the children, then delete the original parent. All in a transaction of course.
Stop using mutable data as a key. It took a long time for DBAs to convince me that artificial (surrogate) keys should be used rather than true data, but this was the use case that finally won me over. Using an artificial key (that never has to change) means this problem disappears totally.
Upvotes: 2