๐๏ธ๋์ SQL : INSERT
์ด๋ฒ ๊ฐ์์์๋ ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐํ๋ ๋ฐฉ๋ฒ์ ์ดํด๋ณผ ๊ฒ์ด๋ค. ์ฐ๋ฆฌ๊ฐ INSERT๋ฅผ ์ฌ์ฉํ๊ธฐ ์ ์ TABLE์ด ์ ๊ตฌ์กฐํ ๋์ด ์๋์ง ๋ณด๊ธฐ ์ํด์๋ ์๋ ์ฝ๋๋ฅผ ์ฌ์ฉํ๋ฉด TBALE์ ๋ชจ์ต์ ํ์ธ ํ ์ ์๋ค.
DESC topic;
MariaDB [opentutorials]> DESC topic;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| title | varchar(100) | NO | | NULL | |
| description | text | YES | | NULL | |
| created | datetime | NO | | NULL | |
| author | varchar(30) | YES | | NULL | |
| profile | varchar(100) | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
6 rows in set (0.023 sec)
์ด์ ๋ฐ์ดํฐ๋ฅผ ๊ธฐ์ ํด๋ณด์ ๊ธฐ์ ํ๊ธฐ ์ํด์๋ INSERT INTO topic์ ์ฌ์ฉํ๋ฉด ๋๋ค. (topic์ ์ฌ์ฉํ TABLE๋ช ์ ์ ๋ ฅํ๋ฉด ๋๋ค.)
INSERT INTO topic(~)VALUES(~);
MariaDB [opentutorials]> INSERT INTO topic (title,description,created,author,profile)
VALUES('MySQL','MySQL is ...',NOW(),'egoing','developer');
Query OK, 1 row affected (0.058 sec)
์ฐ๋ฆฌ๊ฐ ์์ DESC๋ฅผ ํตํด ํ์ธํ TABLE์ ๊ตฌ์กฐ์ ๋ง์ถฐ์ ๊ฐ์ ๋์ ํด์ฃผ๋ฉด ๋๋ค.
์ฐ๋ฆฌ๊ฐ ๊ธฐ์ ํ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๊ธฐ ์ํด์๋ SELECT * FROM topic ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ๋ฉด ๋๋ค.
SELECT * FROM topic;
MariaDB [opentutorials]> SELECT * FROM topic;
+----+-------+--------------+---------------------+--------+-----------+
| id | title | description | created | author | profile |
+----+-------+--------------+---------------------+--------+-----------+
| 1 | MySQL | MySQL is ... | 2023-09-10 15:36:30 | egoing | developer |
+----+-------+--------------+---------------------+--------+-----------+
1 row in set (0.000 sec)
์ฌ๊ธฐ์ ์ ์๊ฐํด ๋ด์ผํ๋ ๊ฒ์ DESC topic๋ช ๋ น๋ฌธ์ ์ฐ๋ฆฌ๊ฐ ๋ง๋ค์ด ๋์ TABLE์ ๊ตฌ์กฐ๋ฅผ ํ์ธ ํ ์ ์๋ ๋ช ๋ น์ด์ธ ๊ฒ์ด๋ค. ์ฆ, ์์์ ํ์ธ ํ ์ ์๋ ๊ฒ์ด๋ค. ๊ทธ๋ฆฌ๊ณ ์ฐ๋ฆฌ๊ฐ ๋ฐ์ดํฐ๋ฅผ ๊ธฐ์ ํ๊ณ ์ ๋ ฅํ ๋ถ๋ถ์ ๊ฐ์ ํ์ธํ๋ ๊ฒ์ ํด๋น TABLE๋ช ์ ์ง๋ช ํ๊ณ SELECT * FROM์ด๋ผ๋ ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด๋ค. ์๋ ์ฝ๋๋ ์ดํ ๋ค๋ฅธ ๋ฐ์ดํฐ ๊ฐ์ ๊ธฐ์ ํ TABLE์ด๋ค.
MariaDB [opentutorials]> INSERT INTO topic (title,description,created,author,profile)
VALUES('ORACLE','ORACLE is ...',NOW(),'egoing','developer');
Query OK, 1 row affected (0.005 sec)
MariaDB [opentutorials]> INSERT INTO topic (title,description,created,author,profile)
VALUES('SQL Server','SQL Server is ...',NOW(),'duru','data administrator');
Query OK, 1 row affected (0.005 sec)
MariaDB [opentutorials]> INSERT INTO topic (title,description,created,author,profile)
VALUES('PostgreSQL','PostgreSQL is ...',NOW(),'taeho','data scientist, developer');
Query OK, 1 row affected (0.004 sec)
MariaDB [opentutorials]> INSERT INTO topic (title,description,created,author,profile)
VALUES('MongoDB','MongoDB is ...',NOW(),'egoing','developer');
Query OK, 1 row affected (0.004 sec)
MariaDB [opentutorials]> SELECT * FROM topic;
+----+------------+-------------------+---------------------+--------+---------------------------+
| id | title | description | created | author | profile |
+----+------------+-------------------+---------------------+--------+---------------------------+
| 1 | MySQL | MySQL is ... | 2023-09-10 15:36:30 | egoing | developer |
| 2 | ORACLE | ORACLE is ... | 2023-09-10 15:51:16 | egoing | developer |
| 3 | SQL Server | SQL Server is ... | 2023-09-10 15:57:25 | duru | data administrator |
| 4 | PostgreSQL | PostgreSQL is ... | 2023-09-10 15:58:31 | taeho | data scientist, developer |
| 5 | MongoDB | MongoDB is ... | 2023-09-10 15:59:20 | egoing | developer |
+----+------------+-------------------+---------------------+--------+---------------------------+
5 rows in set (0.000 sec)