๊ด€๋ฆฌ ๋ฉ”๋‰ด

C-log

๐Ÿ—ƒ๏ธ๋‚˜์˜ SQL : INSERT ๋ณธ๋ฌธ

DB/๐ŸฌMySQL

๐Ÿ—ƒ๏ธ๋‚˜์˜ SQL : INSERT

4:Bee 2023. 9. 10. 16:04
728x90

์ด๋ฒˆ ๊ฐ•์˜์—์„œ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์‚ดํŽด๋ณผ ๊ฒƒ์ด๋‹ค. ์šฐ๋ฆฌ๊ฐ€ 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)

 

728x90
Comments