Guest User

Untitled

a guest
Jan 12th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. -- Creating the customers and orders tables
  2.  
  3. CREATE TABLE customers(
  4. id INT AUTO_INCREMENT PRIMARY KEY,
  5. first_name VARCHAR(100),
  6. last_name VARCHAR(100),
  7. email VARCHAR(100)
  8. );
  9. CREATE TABLE orders(
  10. id INT AUTO_INCREMENT PRIMARY KEY,
  11. order_date DATE,
  12. amount DECIMAL(8,2),
  13. customer_id INT,
  14. FOREIGN KEY(customer_id) REFERENCES customers(id)
  15. );
  16. -- Inserting some customers and orders
  17.  
  18. INSERT INTO customers (first_name, last_name, email)
  19. VALUES ('Boy', 'George', 'george@gmail.com'),
  20. ('George', 'Michael', 'gm@gmail.com'),
  21. ('David', 'Bowie', 'david@gmail.com'),
  22. ('Blue', 'Steele', 'blue@gmail.com'),
  23. ('Bette', 'Davis', 'bette@aol.com');
  24.  
  25. INSERT INTO orders (order_date, amount, customer_id)
  26. VALUES ('2016/02/10', 99.99, 1),
  27. ('2017/11/11', 35.50, 1),
  28. ('2014/12/12', 800.67, 2),
  29. ('2015/01/03', 12.50, 2),
  30. ('1999/04/11', 450.25, 5);
  31.  
  32. -- This INSERT fails because of our fk constraint. No user with id: 98
  33.  
  34.  
  35.  
  36. INSERT INTO orders (order_date, amount, customer_id)
  37. VALUES ('2016/06/06', 33.67, 98);
Add Comment
Please, Sign In to add comment