SQL creates a table of weak entities

I am new to SQL.

I would like to ask when I have an entity with another weak entity. How to create a table in a situation where, if I delete the main object, the weak object will also be deleted?

+5
source share
1 answer

A foreign key with on delete cascade should do the trick:

 CREATE TABLE primary_entity ( id numeric PRIMARY KEY, -- some data fields ); CREATE TABLE weak_entity ( id numeric PRIMARY KEY REFERENCES primary_entity(id) ON DELETE CASCADE, -- some data fields ); 
+4
source

Source: https://habr.com/ru/post/1205006/


All Articles