Advertisement
vencinachev

SQL

Nov 30th, 2020
941
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.39 KB | None | 0 0
  1. CREATE DATABASE uktc;
  2.  
  3. USE uktc;
  4.  
  5. CREATE TABLE students (
  6. id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
  7. firstname VARCHAR(100) NOT NULL,
  8. lastname VARCHAR(100),
  9. age INT,
  10. class INT,
  11. city VARCHAR(100),
  12. email VARCHAR(200)
  13. );
  14.  
  15. INSERT INTO students
  16. VALUES (1, 'Slavi', 'Trifinov', 32, 171, 'Kaspichan', 'slavkata@uktc.com');
  17.  
  18. INSERT INTO students (id, firstname, lastname, age, class, city, email)
  19. VALUES (2, 'Kiro', 'Breika', 45, 171, 'V.T.', 'kiro@uktc.com');
  20.  
  21. INSERT INTO students (firstname, lastname, age)
  22. VALUES ('Ani', 'Borisova', 45);
  23.  
  24. INSERT INTO students
  25. VALUES (5, 'Stamat', 'Ivanov', 32, 171, 'Kaspichan', 'slavkata@uktc.com');
  26.  
  27.  
  28. DELETE FROM students WHERE id = 4;
  29.  
  30. UPDATE students SET city = 'Novi Pazar' WHERE firstname = 'Slavi';
  31.  
  32. SELECT * FROM students;
  33.  
  34.  
  35. CREATE TABLE orders(
  36. id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  37. ordernum INT NOT NULL,
  38. orderdesc VARCHAR(500),
  39. studentid INT,
  40. FOREIGN KEY (studentid) REFERENCES students(id)
  41. );
  42.  
  43. INSERT INTO orders
  44. VALUES (1, 3243, 'obuvki', 1);
  45.  
  46. INSERT INTO orders
  47. VALUES (2, 545, 'uchevnici', 1);
  48.  
  49. INSERT INTO orders
  50. VALUES (3, 545, 'risunki', 1);
  51.  
  52. INSERT INTO orders
  53. VALUES (4, 767, 'drehi', 2);
  54.  
  55. SELECT * FROM orders;
  56.  
  57. UPDATE orders SET ordernum=545 WHERE id=2;
  58.  
  59. SELECT orders.id, orders.ordernum, orders.orderdesc, students.firstname
  60. FROM orders
  61. INNER JOIN students ON orders.studentid = students.id;
  62.  
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement