


You can see a full list of foreign key constraints and triggers in the official PostgreSQL docs Disabling constraints / triggers ON DELETE RESTRICT clause specifies that if a row in the customers table is deleted, the foreign key constraint will be checked, and if there are any matching rows in the orders table, the delete operation will be rejected.ON UPDATE CASCADE specifies that if the customer_id in the customers table is updated, the customer_id in the orders table will also be updated.

Yum.Įxpand your database knowledge with our technical blog.ĬREATE TABLE orders ( order_id serial PRIMARY KEY, customer_id integer NOT NULL, FOREIGN KEY ( customer_id ) REFERENCES customers ( customer_id ) ON UPDATE CASCADE ON DELETE RESTRICT )
#POSTGRES FOREIGN KEY CONSTRAINT HOW TO#
Learn how to use Beekeeper Studio with bite-sized articles. See a list of everything Beekeeper Studio has to offer Work across multiple devices, or share your connections and queries with others. Quickly iterate on a SQL query, view and visualize results, and share with a colleague.Ī spreadsheet like interface to view, navigate, search, and edit your data.Īn easy to use no-code interface to create and alter tables, indexes, foreign keys, and more. How to use foreign keys in PostgreSQL | Beekeeper Studio Beekeeper Studio menuĮxperience a truly modern SQL editor that really sweats the details.
