Saturday, February 22, 2020

TimeStamps

  1. CREATE TABLE comments (
  2. content VARCHAR(100),
  3. created_at TIMESTAMP DEFAULT NOW()
  4. );
  5.  
  6. INSERT INTO comments (content) VALUES('lol what a funny article');
  7.  
  8. INSERT INTO comments (content) VALUES('I found this offensive');
  9.  
  10. INSERT INTO comments (content) VALUES('Ifasfsadfsadfsad');
  11.  
  12. SELECT * FROM comments ORDER BY created_at DESC;
  13.  
  14. CREATE TABLE comments2 (
  15. content VARCHAR(100),
  16. changed_at TIMESTAMP DEFAULT NOW() ON UPDATE CURRENT_TIMESTAMP
  17. );
  18.  
  19. INSERT INTO comments2 (content) VALUES('dasdasdasd');
  20.  
  21. INSERT INTO comments2 (content) VALUES('lololololo');
  22.  
  23. INSERT INTO comments2 (content) VALUES('I LIKE CATS AND DOGS');
  24.  
  25. UPDATE comments2 SET content='THIS IS NOT GIBBERISH' WHERE content='dasdasdasd';
  26.  
  27. SELECT * FROM comments2;
  28.  
  29. SELECT * FROM comments2 ORDER BY changed_at;
  30.  
  31. CREATE TABLE comments2 (
  32. content VARCHAR(100),
  33. changed_at TIMESTAMP DEFAULT NOW() ON UPDATE NOW()
  34. );

No comments:

Post a Comment

Right Joins

-- OUR FIRST RIGHT JOIN (seems the same as a left join?) SELECT * FROM customers RIGHT JOIN orders     ON customers.id = orders.custom...