sql >> Database >  >> RDS >> PostgreSQL

ON DELETE SET NULL in postgres

ON DELETE SET NULL is een standaard beperkingsoptie voor een buitenlandse sleutel.

CREATE TABLE some_child (
    parent_id integer references parent(id) on delete set null
);

of:

ALTER TABLE some_child 
ADD CONSTRAINT parent_id_fk 
FOREIGN KEY (parent_id) REFERENCES parent(id) 
ON DELETE SET NULL;

Zie de documentatie .

Zorg ervoor dat je in toekomstige berichten je PostgreSQL-versie opneemt en leg uit wat je al hebt geprobeerd.




  1. SQL - Haal extra records op, behalve records die zijn gefilterd in waar voorwaarde

  2. CakePHP- en HABTM-modellimietfout

  3. Fix "ERROR 1054 (42S22):Onbekende kolom '...' in 'on-clausule' in MariaDB

  4. MySQL INSERT INTO table SELECT FROM another_table, binnen een PROCEDURE