This commit is contained in:
m-shimizu
2026-09-28 13:26:17 +09:00
parent a2236aae21
commit 5bf83a28e4

View File

@@ -0,0 +1,113 @@
Enter password: *********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 8.0.32 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> CREATE TABLE book_table (
-> \c
mysql> ALTER TABLE book_table
-> ADD book_id INT,
-> ADD bookname VARCHAR(50),
-> ADD author_name VARCHAR(50),
-> ADD price INT,
-> ADD sales,flag INT;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',flag INT' at line 6
mysql> ALTER TABLE book_table
-> -> ADD book_id INT,
-> -> ADD bookname VARCHAR(50),
-> -> ADD author_name VARCHAR(50),
-> -> ADD price INT,
-> -> ADD price INT,\c
mysql> ALTER TABLE book_table
-> ADD book_id INT,
-> ADD book_name VARCHAR(50),
-> ADD author_name VARCHAR(50),
-> ADD price INT,
-> ADD sales_flag INT;
ERROR 1146 (42S02): Table 'book_table.book_table' doesn't exist
mysql> SHOW TABLE;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
mysql> SHOW TABLES;
Empty set (0.00 sec)
mysql> CREATE TABLE book_table (
-> book_id INT,
-> book_name VARCHAR(50),
-> author_name VARCHAR(50),
-> price INT,
-> sales_flag INT
-> );
Query OK, 0 rows affected (0.02 sec)
mysql> INSERT INTO book_table
-> VALUES(10001, 'TwoPeace', '三田英一郎', 420, 1),
-> (10002, '名探偵金田二', '青山ふみや', 460, 1),
-> (20001, '坊ちゃま', '冬目漱岩', 460, 1),
-> (30001, '西方見聞録', '不明', 1000, 1),
-> (40010, '吾輩は犬である', '冬目漱岩', 420, 1);
Query OK, 5 rows affected (0.02 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> SELECT book_name, author_name FROM book_table;
+----------------+-------------+
| book_name | author_name |
+----------------+-------------+
| TwoPeace | 三田英一郎 |
| 名探偵金田二 | 青山ふみや |
| 坊ちゃま | 冬目漱岩 |
| 西方見聞録 | 不明 |
| 吾輩は犬である | 冬目漱岩 |
+----------------+-------------+
5 rows in set (0.00 sec)
mysql> UPDATE book_table SET author_name = 'マール=コーニポロ', salse_flag = 0 WHERE book_id = 30001;
ERROR 1054 (42S22): Unknown column 'salse_flag' in 'field list'
mysql> UPDATE book_table SET author_name = 'マール=コーニポロ', sales_flag = 0 WHERE book_id = 30001;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> SELECT * FROM book_table WHERE sales_flag = 1;
+---------+----------------+-------------+-------+------------+
| book_id | book_name | author_name | price | sales_flag |
+---------+----------------+-------------+-------+------------+
| 10001 | TwoPeace | 三田英一郎 | 420 | 1 |
| 10002 | 名探偵金田二 | 青山ふみや | 460 | 1 |
| 20001 | 坊ちゃま | 冬目漱岩 | 460 | 1 |
| 40010 | 吾輩は犬である | 冬目漱岩 | 420 | 1 |
+---------+----------------+-------------+-------+------------+
4 rows in set (0.00 sec)
mysql> SELECT * FROM book_table WHERE author
-> _name = '冬目漱岩' AND price = 420;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '_name = '冬目漱岩' AND price = 420' at line 2
mysql> SELECT * FROM book_table WHERE author_name = '冬目漱岩' AND price = 420;
+---------+----------------+-------------+-------+------------+
| book_id | book_name | author_name | price | sales_flag |
+---------+----------------+-------------+-------+------------+
| 40010 | 吾輩は犬である | 冬目漱岩 | 420 | 1 |
+---------+----------------+-------------+-------+------------+
1 row in set (0.01 sec)
mysql> DELETE FROM book_table WHERE book_id = 20001;
Query OK, 1 row affected (0.02 sec)
mysql> SELECT * FROM book_table;
+---------+----------------+--------------------+-------+------------+
| book_id | book_name | author_name | price | sales_flag |
+---------+----------------+--------------------+-------+------------+
| 10001 | TwoPeace | 三田英一郎 | 420 | 1 |
| 10002 | 名探偵金田二 | 青山ふみや | 460 | 1 |
| 30001 | 西方見聞録 | マール=コーニポロ | 1000 | 0 |
| 40010 | 吾輩は犬である | 冬目漱岩 | 420 | 1 |
+---------+----------------+--------------------+-------+------------+
4 rows in set (0.00 sec)
mysql>