Advertisement
NellyIvanova29

Практикум БД 25-11

Nov 25th, 2021
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 10.26 KB | None | 0 0
  1.  
  2. Setting environment for using XAMPP for Windows.
  3. nelly@NELLYIVANOVA c:\xampp
  4. # mysql -uroot
  5. Welcome to the MariaDB monitor.  Commands end with ; or \g.
  6. Your MariaDB connection id is 16
  7. Server version: 10.4.21-MariaDB mariadb.org binary distribution
  8.  
  9. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  10.  
  11. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  12.  
  13. MariaDB [(none)]> create database cont;
  14. Query OK, 1 row affected (0.001 sec)
  15.  
  16. MariaDB [(none)]> use cont;
  17. Database changed
  18. MariaDB [cont]>  create table triangles(
  19.     ->     id MEDIUMINT NOT NULL AUTO_INCREMENT,
  20.     ->      side1 float(3,2) DEFAULT '0' NOT NULL,
  21.     -> side2 float(3,2) DEFAULT '0' NOT NULL,
  22.     -> side3 float(3,2) DEFAULT '0' NOT NULL);
  23. ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
  24. MariaDB [cont]>  create table triangles(
  25.     ->  PRIMARY KEY   id MEDIUMINT NOT NULL AUTO_INCREMENT,
  26.     ->      side1 float(3,2) DEFAULT '0' NOT NULL,
  27.     -> side2 float(3,2) DEFAULT '0' NOT NULL,
  28.     -> side3 float(3,2) DEFAULT '0' NOT NULL);
  29. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'MEDIUMINT NOT NULL AUTO_INCREMENT,
  30.     side1 float(3,2) DEFAULT '0' NOT NULL...' at line 2
  31. MariaDB [cont]>
  32. MariaDB [cont]>  create table triangles(
  33.     ->    id INT AUTO_INCREMENT,
  34.     ->      side1 float(3,2) DEFAULT '0' NOT NULL,
  35.     -> side2 float(3,2) DEFAULT '0' NOT NULL,
  36.     -> side3 float(3,2) DEFAULT '0' NOT NULL,
  37.     -> primary key(id));
  38. Query OK, 0 rows affected (0.015 sec)
  39.  
  40. MariaDB [cont]>    create table types(
  41.     ->    id INT NOT NULL,
  42.     ->     kind VARCHAR(16),
  43.     -> primary key(id));
  44. Query OK, 0 rows affected (0.009 sec)
  45.  
  46. MariaDB [cont]> INSERT INTO types (id, kind) VALUES("1", "illegal");
  47. Query OK, 1 row affected (0.017 sec)
  48.  
  49. MariaDB [cont]>
  50. MariaDB [cont]> INSERT INTO types (id, kind) VALUES("2", "equilateral");
  51. Query OK, 1 row affected (0.002 sec)
  52.  
  53. MariaDB [cont]> INSERT INTO types (id, kind) VALUES("3", "isosceles");
  54. Query OK, 1 row affected (0.008 sec)
  55.  
  56. MariaDB [cont]> INSERT INTO types (id, kind) VALUES("4", "scalene");
  57. Query OK, 1 row affected (0.008 sec)
  58.  
  59. MariaDB [cont]> INSERT INTO types (id, kind) VALUES("5", "acute");
  60. Query OK, 1 row affected (0.002 sec)
  61.  
  62. MariaDB [cont]> INSERT INTO types (id, kind) VALUES("6", "obtuse");
  63. Query OK, 1 row affected (0.008 sec)
  64.  
  65. MariaDB [cont]>
  66. MariaDB [cont]> INSERT INTO types (id, kind) VALUES("7", "right");
  67. Query OK, 1 row affected (0.002 sec)
  68.  
  69. MariaDB [cont]> INSERT INTO triangles (id, side1, side2, side3) VALUES("1", 10,20,30);
  70. Query OK, 1 row affected, 3 warnings (0.010 sec)
  71.  
  72. MariaDB [cont]> select* from triangles;
  73. +----+-------+-------+-------+
  74. | id | side1 | side2 | side3 |
  75. +----+-------+-------+-------+
  76. |  1 |  9.99 |  9.99 |  9.99 |
  77. +----+-------+-------+-------+
  78. 1 row in set (0.009 sec)
  79.  
  80. MariaDB [cont]> delete* from triangles;
  81. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '* from triangles' at line 1
  82. MariaDB [cont]> INSERT INTO triangles (id, side1, side2, side3) VALUES("1", '10.00','20.00','30.00');
  83. ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
  84. MariaDB [cont]> INSERT INTO triangles (id, side1, side2, side3) VALUES("2", '10.00','20.00','30.00');
  85. Query OK, 1 row affected, 3 warnings (0.007 sec)
  86.  
  87. MariaDB [cont]> select* from triangles;
  88. +----+-------+-------+-------+
  89. | id | side1 | side2 | side3 |
  90. +----+-------+-------+-------+
  91. |  1 |  9.99 |  9.99 |  9.99 |
  92. |  2 |  9.99 |  9.99 |  9.99 |
  93. +----+-------+-------+-------+
  94. 2 rows in set (0.000 sec)
  95.  
  96. MariaDB [cont]>  create table triangle1(
  97.     ->    id INT AUTO_INCREMENT,
  98.     ->      side1 decimal(3,2) DEFAULT '0' NOT NULL,
  99.     -> side2 decimal(3,2) DEFAULT '0' NOT NULL,
  100.     -> side3 decimal(3,2) DEFAULT '0' NOT NULL,
  101.     -> primary key(id));
  102. Query OK, 0 rows affected (0.017 sec)
  103.  
  104. MariaDB [cont]>
  105. MariaDB [cont]> INSERT INTO triangles1 (id, side1, side2, side3) VALUES("1", 10,20,30);
  106. ERROR 1146 (42S02): Table 'cont.triangles1' doesn't exist
  107. MariaDB [cont]> INSERT INTO triangle1 (id, side1, side2, side3) VALUES("1", 10,20,30);
  108. Query OK, 1 row affected, 3 warnings (0.009 sec)
  109.  
  110. MariaDB [cont]> select* from tables;
  111. ERROR 1146 (42S02): Table 'cont.tables' doesn't exist
  112. MariaDB [cont]> select* from triangle1;
  113. +----+-------+-------+-------+
  114. | id | side1 | side2 | side3 |
  115. +----+-------+-------+-------+
  116. |  1 |  9.99 |  9.99 |  9.99 |
  117. +----+-------+-------+-------+
  118. 1 row in set (0.000 sec)
  119.  
  120. MariaDB [cont]>  create table triangle2(
  121.     ->    id INT AUTO_INCREMENT,
  122.     ->      side1 decimal(5,2) DEFAULT '0' NOT NULL,
  123.     -> side2 decimal(5,2) DEFAULT '0' NOT NULL,
  124.     -> side3 decimal(5,2) DEFAULT '0' NOT NULL,
  125.     -> primary key(id));
  126. Query OK, 0 rows affected (0.012 sec)
  127.  
  128. MariaDB [cont]> INSERT INTO triangle2 (id, side1, side2, side3) VALUES("1", 10,20,30);
  129. Query OK, 1 row affected (0.009 sec)
  130.  
  131. MariaDB [cont]> INSERT INTO triangle2 (id, side1, side2, side3) VALUES("1", 20,10,20);
  132. ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
  133. MariaDB [cont]> INSERT INTO triangle2 (id, side1, side2, side3) VALUES("2", 20,10,20);
  134. Query OK, 1 row affected (0.007 sec)
  135.  
  136. MariaDB [cont]> INSERT INTO triangle2 (id, side1, side2, side3) VALUES("3", 20,20,20);
  137. Query OK, 1 row affected (0.008 sec)
  138.  
  139. MariaDB [cont]> INSERT INTO triangle2 (id, side1, side2, side3) VALUES("4", 30,50,40);
  140. Query OK, 1 row affected (0.008 sec)
  141.  
  142. MariaDB [cont]> select* from triangle2;
  143. +----+-------+-------+-------+
  144. | id | side1 | side2 | side3 |
  145. +----+-------+-------+-------+
  146. |  1 | 10.00 | 20.00 | 30.00 |
  147. |  2 | 20.00 | 10.00 | 20.00 |
  148. |  3 | 20.00 | 20.00 | 20.00 |
  149. |  4 | 30.00 | 50.00 | 40.00 |
  150. +----+-------+-------+-------+
  151. 4 rows in set (0.001 sec)
  152.  
  153. MariaDB [cont]> INSERT INTO triangle2 (id, side1, side2, side3) VALUES("5", 167.41,160.87,32.05 );
  154. Query OK, 1 row affected (0.008 sec)
  155.  
  156. MariaDB [cont]> INSERT INTO triangle2 (id, side1, side2, side3) VALUES("6",17.95,153.41,102.11 );
  157. Query OK, 1 row affected (0.002 sec)
  158.  
  159. MariaDB [cont]> INSERT INTO triangle2 (id, side1, side2, side3) VALUES("7",195.85,133.22,189.62);
  160. Query OK, 1 row affected (0.002 sec)
  161.  
  162. MariaDB [cont]>
  163. MariaDB [cont]> select* from triangle2 where side1+side2 >side3 or side1+side3>side2 or side2+side3>side1;
  164. +----+--------+--------+--------+
  165. | id | side1  | side2  | side3  |
  166. +----+--------+--------+--------+
  167. |  1 |  10.00 |  20.00 |  30.00 |
  168. |  2 |  20.00 |  10.00 |  20.00 |
  169. |  3 |  20.00 |  20.00 |  20.00 |
  170. |  4 |  30.00 |  50.00 |  40.00 |
  171. |  5 | 167.41 | 160.87 |  32.05 |
  172. |  6 |  17.95 | 153.41 | 102.11 |
  173. |  7 | 195.85 | 133.22 | 189.62 |
  174. +----+--------+--------+--------+
  175. 7 rows in set (0.004 sec)
  176.  
  177. MariaDB [cont]> select* from triangles where side1+side2 >side3 and side1+side3>side2 and side2+side3>side1;
  178. +----+-------+-------+-------+
  179. | id | side1 | side2 | side3 |
  180. +----+-------+-------+-------+
  181. |  1 |  9.99 |  9.99 |  9.99 |
  182. |  2 |  9.99 |  9.99 |  9.99 |
  183. +----+-------+-------+-------+
  184. 2 rows in set (0.002 sec)
  185.  
  186. MariaDB [cont]> select* from triangle2 where side1+side2 >side3 and side1+side3>side2 and side2+side3>side1 ORDER BY side1 ASC;
  187. +----+--------+--------+--------+
  188. | id | side1  | side2  | side3  |
  189. +----+--------+--------+--------+
  190. |  2 |  20.00 |  10.00 |  20.00 |
  191. |  3 |  20.00 |  20.00 |  20.00 |
  192. |  4 |  30.00 |  50.00 |  40.00 |
  193. |  5 | 167.41 | 160.87 |  32.05 |
  194. |  7 | 195.85 | 133.22 | 189.62 |
  195. +----+--------+--------+--------+
  196. 5 rows in set (0.002 sec)
  197.  
  198. MariaDB [cont]> SELECT side1 + side2 + side3 as "Perimeter" FROM triangle2;
  199. +-----------+
  200. | Perimeter |
  201. +-----------+
  202. |     60.00 |
  203. |     50.00 |
  204. |     60.00 |
  205. |    120.00 |
  206. |    360.33 |
  207. |    273.47 |
  208. |    518.69 |
  209. +-----------+
  210. 7 rows in set (0.001 sec)
  211.  
  212. MariaDB [cont]> SELECT id, side1 + side2 + side3 as "Perimeter" FROM triangle2  where side1+side2 >side3 and side1+side3>side2 and side2+side3>side1 ORDER BY side1 ASC;
  213. +----+-----------+
  214. | id | Perimeter |
  215. +----+-----------+
  216. |  2 |     50.00 |
  217. |  3 |     60.00 |
  218. |  4 |    120.00 |
  219. |  5 |    360.33 |
  220. |  7 |    518.69 |
  221. +----+-----------+
  222. 5 rows in set (0.001 sec)
  223.  
  224. MariaDB [cont]> SELECT id, side1 + side2 + side3 as "Perimeter" FROM triangle2  where side1+side2 >side3 and side1+side3>side2 and side2+side3>side1 ORDER BY Perimeter DESC;
  225. +----+-----------+
  226. | id | Perimeter |
  227. +----+-----------+
  228. |  7 |    518.69 |
  229. |  5 |    360.33 |
  230. |  4 |    120.00 |
  231. |  3 |     60.00 |
  232. |  2 |     50.00 |
  233. +----+-----------+
  234. 5 rows in set (0.001 sec)
  235.  
  236. MariaDB [cont]>
  237. MariaDB [cont]> SELECT id, side1 + side2 + side3 as "Perimeter" FROM triangle2  where side1+side2 >side3 and side1+side3>side2 and side2+side3>side1 ORDER BY Perimeter ASC;
  238. +----+-----------+
  239. | id | Perimeter |
  240. +----+-----------+
  241. |  2 |     50.00 |
  242. |  3 |     60.00 |
  243. |  4 |    120.00 |
  244. |  5 |    360.33 |
  245. |  7 |    518.69 |
  246. +----+-----------+
  247. 5 rows in set (0.001 sec)
  248.  
  249. MariaDB [cont]> SELECT id, SQRT((side1+side2+side3)/2*((side1+side2+side3)/2-side1)*((side1+side2+side3)/2-side2)*((side1+side2+side3)/2-side3)) as "Area" FROM triangle2  where side1+side2 >side3 and side1+side3>side2 and side2+side3>side1 ORDER BY Area ASC;
  250. +----+--------------------+
  251. | id | Area               |
  252. +----+--------------------+
  253. |  2 |  96.82458365518542 |
  254. |  3 | 173.20508075688772 |
  255. |  4 |                600 |
  256. |  5 |  2562.697571787604 |
  257. |  7 | 12033.821205647631 |
  258. +----+--------------------+
  259. 5 rows in set (0.009 sec)
  260.  
  261. MariaDB [cont]>MariaDB [cont]> select
  262.     ->     case
  263.     ->         when side1+side2 <side3 or side1+side3<side2 or side2+side3<side1 then "Not A Triangle"
  264.     ->         when side1=side2 and side2=side3 then "Equilateral"
  265.     ->         when side1=side2 or side1=side3 or side2=side3 then "Isosceles"
  266.     ->         when side1<>side2 and side2<>side3 then "Scalene"
  267.     ->
  268.     ->     end as triangles_type
  269.     ->     from triangle2;
  270. +----------------+
  271. | triangles_type |
  272. +----------------+
  273. | Scalene        |
  274. | Isosceles      |
  275. | Equilateral    |
  276. | Scalene        |
  277. | Scalene        |
  278. | Not A Triangle |
  279. | Scalene        |
  280. +----------------+
  281. 7 rows in set (0.008 sec)
  282.  
  283. MariaDB [cont]>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement