Search notes:

SAS: proc sql / foreign key constraints

Dropping the child table of a parent/child relationship

/*   Create a parent-child relationship between two tables
     using a primary and a foreign key: */
proc sql;
  
  create table tq84_parent (
     id   num,
     val char(25),
  /* ----------------------------------- */
     constraint tq84_pk primary key (id)
  );

  create table tq84_child (
     id_parent num,
     val       char(25),
  /* ----------------------------------- */
     constraint tq84_fk foreign key (id_parent) references tq84_parent
  );

quit;

/* SAS does not allow to drop the child of a foreign key
   relation ship!
   The following drop statement results in a
      ERROR: A rename/delete/replace attempt
             is not allowed for a data set
             involved in a referential integrity
             constraint. 
*/       
proc sql;
   drop table tq84_child;
quit;

/* So, the foreign key must explicitely be dropped before the
   child table can be dropped:
*/
proc sql;
  alter table tq84_child drop foreign key tq84_fk;

  drop table tq84_child;
quit;
Github repository about-SAS, path: /programming/proc/sql/constraints/foreign-key/drop-child-table.sas

See also

proc SQL - constraints
dictionary.referential_constraints
proc sql
General notes about foreign keys in SQL

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Companie...', 1758200622, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Companies-Products/SAS/programming/proc/sql/constraints/foreign-key(89): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78