Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.76 KB | None | 0 0
  1. DROP DATABASE IF EXISTS service_community;
  2. CREATE DATABASE service_community CHARACTER SET 'utf8';
  3. USE service_community;
  4.  
  5. -- Table users
  6.  
  7. CREATE TABLE users (
  8. id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  9. mail VARCHAR(30) NOT NULL,
  10. passweird VARCHAR(20) NOT NULL,
  11. nickname VARCHAR(20) NOT NULL,
  12. adress VARCHAR(60),
  13. zip_code VARCHAR(15),
  14. city VARCHAR(40),
  15. country VARCHAR(30),
  16. cellphone VARCHAR(20),
  17. phone VARCHAR(20),
  18. date_inscription DATE,
  19. PRIMARY KEY (id)
  20. )
  21. ENGINE = INNODB;
  22.  
  23. -- Table services
  24.  
  25. CREATE TABLE services (
  26. id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  27. id_user_from INT UNSIGNED NOT NULL,
  28. name VARCHAR(20) NOT NULL,
  29. description TEXT NOT NULL,
  30. adress VARCHAR(30) NOT NULL,
  31. zip_code VARCHAR(15) NOT NULL,
  32. city VARCHAR(40) NOT NULL,
  33. country VARCHAR(30) NOT NULL,
  34. date_time DATETIME NOT NULL,
  35. additional_information TEXT,
  36. PRIMARY KEY (id)
  37. )
  38. ENGINE = INNODB;
  39.  
  40. -- Table services-users
  41.  
  42. CREATE TABLE services_users (
  43. id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  44. id_service INT UNSIGNED NOT NULL,
  45. id_user INT UNSIGNED NOT NULL,
  46. date_time_inscription DATETIME NOT NULL,
  47. PRIMARY KEY (id)
  48. )
  49. ENGINE = INNODB;
  50.  
  51. -- Table messages
  52.  
  53. CREATE TABLE messages (
  54. id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  55. id_user_from INT UNSIGNED NOT NULL,
  56. id_user_to INT UNSIGNED NOT NULL,
  57. content TEXT NOT NULL,
  58. date_time_sended DATETIME NOT NULL,
  59. PRIMARY KEY (id)
  60. )
  61. ENGINE = INNODB;
  62.  
  63. -- Users creation
  64.  
  65. INSERT INTO users (mail, passweird, nickname)
  66. VALUE ('testytasty@toast.com', 'apassweird', 'Tasty'),
  67. ('unmail@free.ru', 'aweirdpassweird', 'Toast'),
  68. ('thetoast@toaster.fr', '1234', 'John'),
  69. ('amail@mail.com', '4256', 'Banana'),
  70. ('thisisnotamail@mail.com', '6969', 'Caraba'),
  71. ('banana@gree.com', '666', 'Veratisen'),
  72. ('stupefix@snape.avada', '934', 'Giiny'),
  73. ('alohomora@severus.keda', 'crucio', 'Lockhart'),
  74. ('potterXdraco@tyrion.com', '0000', 'Sprout'),
  75. ('slughornXjedusor@granger.ron', 'mangetesmangesmorts', 'Dumblehumbledore');
  76.  
  77. -- Messages creation
  78.  
  79. INSERT INTO messages (id_user_from, id_user_to, content, date_time_sended)
  80. VALUE (1, 2, 'This is a message.', '2016-10-06 15:55:45'),
  81. (4, 3, 'This is a message.', '2016-10-06 15:56:45'),
  82. (9, 2, 'This is a message.', '2016-10-06 15:57:45'),
  83. (5, 9, 'This is a message.', '2016-10-06 15:58:45'),
  84. (1, 4, 'This is a message.', '2016-10-06 15:54:45'),
  85. (8, 7, 'This is a message.', '2016-10-06 15:30:45'),
  86. (3, 2, 'This is a message.', '2016-10-06 16:54:45'),
  87. (6, 4, 'This is a message.', '2016-10-06 13:54:45'),
  88. (5, 9, 'This is a message.', '2016-10-06 12:54:45'),
  89. (3, 7, 'This is a message.', '2016-10-06 11:54:45'),
  90. (9, 6, 'This is a message.', '2016-10-06 09:11:45'),
  91. (9, 1, 'This is a message.', '2016-10-06 01:54:00'),
  92. (6, 4, 'This is a message.', '2016-10-06 13:44:45'),
  93. (3, 7, 'This is a message.', '2016-10-06 19:54:45'),
  94. (2, 5, 'This is a message.', '2016-10-06 10:15:45'),
  95. (3, 4, 'This is a message.', '2016-10-06 17:33:45'),
  96. (8, 5, 'This is a message.', '2016-10-06 13:52:45'),
  97. (4, 9, 'This is a message.', '2016-10-06 14:54:45'),
  98. (2, 4, 'This is a message.', '2016-10-06 16:50:45'),
  99. (3, 7, 'This is a message.', '2016-10-06 18:53:45'),
  100. (4, 9, 'This is a message.', '2016-10-06 19:13:45'),
  101. (3, 10, 'This is a message.', '2016-10-06 15:34:45'),
  102. (1, 10, 'This is a message.', '2016-10-06 13:56:45'),
  103. (10, 1, 'This is a message.', '2016-10-06 14:49:45'),
  104. (10, 3, 'This is a message.', '2016-10-06 20:01:45');
  105.  
  106. -- Update of profiles
  107.  
  108. UPDATE users
  109. SET adress = '4 Privet drive', zip_code = '93666', city = 'Little Whinging', country = 'Sweden', cellphone = '06666666', phone = '011111111', date_inscription= '2015-05-15'
  110. WHERE id = 1;
  111. UPDATE users
  112. SET adress = '4 Privet drive', zip_code = '93666', city = 'Little Whinging', country = 'Sweden', cellphone = '06666666', phone = '011111111', date_inscription= '2015-05-15'
  113. WHERE id = 2;
  114. UPDATE users
  115. SET adress = '4 Privet drive', zip_code = '93666', city = 'Little Whinging', country = 'Sweden', cellphone = '06666666', phone = '011111111', date_inscription= '2015-05-15'
  116. WHERE id = 3;
  117. UPDATE users
  118. SET adress = '4 Privet drive', zip_code = '93666', city = 'Little Whinging', country = 'Sweden', cellphone = '06666666', phone = '011111111', date_inscription= '2015-05-15'
  119. WHERE id = 4;
  120. UPDATE users
  121. SET adress = '4 Privet drive', zip_code = '93666', city = 'Little Whinging', country = 'Sweden', cellphone = '06666666', phone = '011111111', date_inscription= '2015-05-15'
  122. WHERE id = 5;
  123. UPDATE users
  124. SET adress = '4 Privet drive', zip_code = '93666', city = 'Little Whinging', country = 'Sweden', cellphone = '06666666', phone = '011111111', date_inscription= '2015-05-15'
  125. WHERE id = 6;
  126. UPDATE users
  127. SET adress = '4 Privet drive', zip_code = '93666', city = 'Little Whinging', country = 'Sweden', cellphone = '06666666', phone = '011111111', date_inscription= '2015-05-15'
  128. WHERE id = 7;
  129. UPDATE users
  130. SET adress = '4 Privet drive', zip_code = '93666', city = 'Little Whinging', country = 'Sweden', cellphone = '06666666', phone = '011111111', date_inscription= '2015-05-15'
  131. WHERE id = 8;
  132. UPDATE users
  133. SET adress = '4 Privet drive', zip_code = '93666', city = 'Little Whinging', country = 'Sweden', cellphone = '06666666', phone = '011111111', date_inscription= '2015-05-15'
  134. WHERE id = 9;
  135. UPDATE users
  136. SET adress = '4 Privet drive', zip_code = '93666', city = 'Little Whinging', country = 'Sweden', cellphone = '06666666', phone = '011111111', date_inscription= '2015-05-15'
  137. WHERE id = 10;
  138.  
  139. -- Display all conversations from one user (here 10)
  140.  
  141. SELECT * FROM messages
  142. WHERE id_user_from = 10
  143. OR id_user_to = 10
  144. ORDER BY date_time_sended DESC;
  145.  
  146. -- Display all messages between two users
  147.  
  148. SELECT * FROM messages
  149. WHERE (id_user_from = 10 AND id_user_to = 3)
  150. OR (id_user_from = 3 AND id_user_to = 10);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement