Advertisement
Guest User

SQL making stack-overflow trip

a guest
Feb 25th, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.62 KB | None | 0 0
  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;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement