SHARE
TWEET

SQL making stack-overflow trip

a guest Feb 25th, 2016 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     CREATE TABLE parent (
  3.       pid INTEGER PRIMARY KEY,
  4.       expired CHAR(1));
  5.      
  6.       CREATE TABLE child (
  7.         cid INTEGER PRIMARY KEY,
  8.         f_pid INTEGER NOT NULL REFERENCES parent(pid) );
  9.    
  10.     INSERT INTO parent VALUES (1,'0');
  11.     INSERT INTO parent VALUES (2,'1');
  12.     INSERT INTO parent VALUES (3,'0');
  13.    
  14.     INSERT INTO child VALUES (1,1);
  15.     INSERT INTO child VALUES (2,1);
  16.    
  17.     -- this should fail as the parent has expired=1
  18.     INSERT INTO child VALUES (3,2);
  19.    
  20.     -- this should also fail as it has children referencing it
  21.     UPDATE parent SET expired='1' WHERE pid=1;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top