Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ON UPDATE RESTRICT do?

... user_id INTEGER NOT NULL,  CONSTRAINT fk_user_meta FOREIGN KEY (user_id)     REFERENCES users (id) ON DELETE CASCADE ON UPDATE RESTRICT 

I know from here that ON DELETE CASCADE means that if I delete a row from the users table, then the associated row from the user meta table will be removed too. But what does ON UPDATE RESTRICT do?

like image 239
Alex Avatar asked Dec 03 '11 23:12

Alex


People also ask

When to use on delete restrict?

When do we use ON DELETE RESTRICT? Whenever we don't want "orphan" rows in the database! We don't want to delete a customer from the CUSTOMER table if there are any orders for that customer in the ORDERS table.

Does On Update Cascade also delete?

CASCADE. It is used in conjunction with ON DELETE or ON UPDATE. It means that the child data is either deleted or updated when the parent data is deleted or updated.

What is the difference between Cascade and restrict?

The CASCADE option directs the DBMS Server to revoke the specified privileges plus all privileges and objects that depend on the privileges being revoked. The RESTRICT option directs the DBMS Server not to revoke the specified privilege if there are any dependent privileges or objects.

What is restrict in MySQL?

RESTRICT : Rejects the delete or update operation for the parent table. Specifying RESTRICT (or NO ACTION ) is the same as omitting the ON DELETE or ON UPDATE clause. NO ACTION : A keyword from standard SQL. In MySQL, equivalent to RESTRICT .


1 Answers

RESTRICT prevents the action from happening if there's any foreign keys that rely on the field that's being changed.

like image 151
Chris Eberle Avatar answered Oct 13 '22 06:10

Chris Eberle