title: why SQL cannot delete parent row when references are deleted
body: <p>I created a database that contains some tables and they are related to each other. But the problem is that I can deleted tthe record from the child tables, however not from the parent table.</p>
  
  <p>See my SQL Tables structure code </p>
  
  <pre><code>User:
  
  CREATE TABLE "User"
  (
      ID INT generated by default as identity PRIMARY KEY,
      username varchar(55) NOT NULL,
      password varchar(65) NOT NULL,
      "role" varchar(65) NOT NULL
  );
  
  Activity:
  
  CREATE TABLE Activity
  (
      ID INT generated by default as identity PRIMARY KEY,
      "time" varchar(55) NOT NULL,
      "date" varchar(55) NOT NULL,
      purgedDocumentName varchar(55) NOT NULL,
      user_ID INTEGER,
      CONSTRAINT fk_activity_usr FOREIGN KEY (user_ID)
      REFERENCES EDMSDATABASE."User"(ID)
  );
  
  Message:
  
  CREATE TABLE Message
  (
      ID INT generated by default as identity PRIMARY KEY,
      title varchar(255) NOT NULL,
      subject varchar(255) NOT NULL,
      description varchar(255) NOT NULL,
      deadline varchar(255) NOT NULL
  );
  
  
  WorkflowMessage:
  
  CREATE TABLE WorkflowMessage
  (
      user_ID INTEGER ,
      message_ID INTEGER ,
      CONSTRAINT fk_usr_user FOREIGN KEY (user_ID)
      REFERENCES EDMSDATABASE."User"(ID),
  
      CONSTRAINT fk_usr_msg FOREIGN KEY (message_ID)
      REFERENCES EDMSDATABASE.Message(ID)
  );
  
  
  Document:
  
  CREATE TABLE Document
  (
      ID INT generated by default as identity PRIMARY KEY,
      "name" varchar(255) NOT NULL,
      description varchar(255) NOT NULL,
      location varchar(255) NOT NULL,
      createdDate varchar(255) NOT NULL,
      status varchar(255) NOT NULL,
      user_ID INTEGER ,
  
      CONSTRAINT fk_doc_user FOREIGN KEY (user_ID)
      REFERENCES EDMSDATABASE."User"(ID)
  );
  
  
  Version:
  
  CREATE TABLE Version
  (
      ID INT generated by default as identity PRIMARY KEY,
      versionNumber INTEGER NOT NULL,
      mofiedDate varchar(255) NOT NULL,
      newLocation varchar(255) NOT NULL,
      document_ID INTEGER ,
  
      CONSTRAINT fk_doc_version FOREIGN KEY (document_ID)
      REFERENCES EDMSDATABASE.Document(ID)
  );
  
  
  Trash
  
  CREATE TABLE RemovedDocument
  (
      ID INTEGER PRIMARY KEY,
        FOREIGN KEY (ID) REFERENCES EDMSDATABASE.Document(ID),
      newLocation VARCHAR(255)
  );
  
  
  
  Historical Document
  
  CREATE TABLE HistoricalDocument
  (
      ID INTEGER PRIMARY KEY,
        FOREIGN KEY (ID) REFERENCES EDMSDATABASE.Document(ID),
      newLocation VARCHAR(255),
      retentionDate VARCHAR(12)
  );
  
  
  Group
  
  CREATE TABLE "Group"
  (
      "rights" INTEGER NOT NULL,
      user_ID INTEGER ,
      document_ID INTEGER ,
      CONSTRAINT fk_group_document FOREIGN KEY (document_ID)
      REFERENCES EDMSDATABASE.DOCUMENT(ID),
  
      CONSTRAINT fk_group_usr FOREIGN KEY (user_ID)
      REFERENCES EDMSDATABASE."User"(ID)
  );
  </code></pre>