In PostgreSQL what is the default action over a child table referencing with foreign keys a parent table, on the UPDATE / DELETE
events?
The possible ones listed are the following:
NO ACTION | RESTRICT | CASCADE | SET NULL | SET DEFAULT
I imagine it could be NO ACTION
, but the official documentation does not specify it in the events paragraph of the SELECT statement specs (unfortunately, the deeplink to the paragraph is not referenceable).
To drop a foreign key from a table, use the ALTER TABLE clause with the name of the table (in our example, student ) followed by the clause DROP CONSTRAINT with the name of the foreign key constraint. In our example, the name of this constraint is fk_student_city_id .
A foreign key containing null values cannot match the values of a parent key, since a parent key by definition can have no null values. However, a null foreign key value is always valid, regardless of the value of any of its non-null parts.
The FOREIGN KEY Constraint is a column or list of columns which points to the PRIMARY KEY of another table. you cannot simply update either child or parent table information in a Foreign Key relationship and that's the the purpose of it. If you want to update them, you have to enable, Update CASCADE on Parent table.
It's right there in the description of the REFERENCES
clause
Quote from the manual
NO ACTION
.... This is the default action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With