Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. DROP TABLE IF EXISTS pets CASCADE;
  2. DROP TABLE IF EXISTS owners CASCADE;
  3. DROP TABLE IF EXISTS pets_owners;
  4.  
  5. CREATE TABLE pets (
  6. id serial PRIMARY KEY,
  7. name varchar(255),
  8. age integer,
  9. kind text
  10. );
  11.  
  12. CREATE TABLE owners (
  13. id serial PRIMARY KEY,
  14. name text,
  15. is_alergic boolean
  16. );
  17.  
  18. CREATE TABLE pets_owners (
  19. id serial PRIMARY KEY,
  20. pet_id integer NOT NULL REFERENCES pets ON DELETE CASCADE,
  21. owner_id integer NOT NULL REFERENCES owners ON DELETE CASCADE,
  22. role text
  23. );
  24.  
  25.  
  26. INSERT INTO pets (name, age, kind)
  27. VALUES ('Chucky', 102, 'Goat');
  28.  
  29. INSERT INTO owners (name, is_alergic)
  30. VALUES ('Glen', true);
  31.  
  32. INSERT INTO pets_owners (pet_id, owner_id, role)
  33. VALUES (1, 1, 'Father')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement