ޭ mysql> INSERT INTO users SET id = 1, name = 'miki_bene'; Query OK, 1 row affected (0.01 sec) !" ಉ͡ id ͷΛೖΕΑ͏ͱ͢ΔͱΤϥʔ mysql> INSERT INTO users SET id = 1, name = 'miki_bene2'; ERROR 1062 (23000): Duplicate entry '1' for key 'users.PRIMARY'
NOT NULL, name VARCHAR(32) NOT NULL, created_at DATETIME NOT NULL, PRIMARY KEY (`id`) ); !" ϒϩάΛද͢ςʔϒϧɻ user_id ϒϩάΛ͍࣋ͬͯΔϢʔβʔͷid CREATE TABLE blogs ( id BIGINT UNSIGNED NOT NULL, user_id BIGINT UNSIGNED NOT NULL, title VARCHAR(50) NOT NULL, description VARCHAR(512), PRIMARY KEY (id) );
(݁Ռলུ) !" ߜΓࠐΈʹ WHERE ۟Λ͚Δ(ޙड़) !" id ͕ 1 ͷϨίʔυΛݕࡧ mysql> SELECT * FROM users WHERE id = 1; +----+-----------+---------------------+ | id | name | created_at | +----+-----------+---------------------+ | 1 | ͯͳଠ | 2021-08-17 12:00:00 | +----+-----------+---------------------+ 1 row in set (0.00 sec) .Z42-.Z42-ٛنؒٝ٤تُؼٖٜؓ4&-&$5啶乃
SET name = 'miki_bene' WHERE id = 1; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT * FROM users WHERE id = 1; +----+-----------+---------------------+ | id | name | created_at | +----+-----------+---------------------+ | 1 | miki_bene | 2021-08-17 12:00:00 | +----+-----------+---------------------+ 1 row in set (0.01 sec) !" ҙ! WHERE ۟Ͱࢦఆ͠ͳ͍߹શ݅ߋ৽ରʹͳΔ mysql> UPDATE users SET name = "miki_bene"; .Z42-.Z42-ٛنؒٝ٤تُؼٖٜؓ61%"5&啶乃
!" id͕1ͷϨίʔυΛݕࡧ SELECT * FROM users WHERE id = 1; !" id͕1Ͱͳ͍ϨίʔυΛݕࡧ SELECT * FROM users WHERE id !# 1; !" created_at ͕ 2021-08-17 12:00:00 ΑΓେ͖͍ϨίʔυΛݕࡧ SELECT * FROM users WHERE created_at > '2021-08-17 12:00:00';
12:00:00 ΑΓେ͖͍ϨίʔυΛݕࡧ !" name͕"ͯͳ"͔Β࢝·ΔϨίʔυΛݕࡧ !" `LIKE`จࣈྻͷ෦Ұக(`%`͕ϫΠϧυΧʔυͰ, ҙͷ0จࣈҎ্ͷจࣈྻʹͳΔ) SELECT * FROM users WHERE created_at > '2021-08-17 12:00:00' AND name LINE 'ͯͳ%'; !" id͕1͔2͔3ͷϨίʔυΛݕࡧ SELECT * FROM users WHERE id = 1 OR id = 2 OR id = 3; !" ্ͷSQLΛINΛͬͯ SELECT * FROM users WHERE id IN (1, 2, 3);
!" = 1ϖʔδ3݅·Ͱදࣔ͢Δ !" 1ϖʔδ SELECT * FROM users ORDER BY created_at LIMIT 3 OFFSET 0; !" 2ϖʔδ SELECT * FROM users ORDER BY created_at LIMIT 3 OFFSET 3; !" 3ϖʔδ SELECT * FROM users ORDER BY created_at LIMIT 3 OFFSET 6;