TIL 06 : mysql_INSERT & SELECT

SQL?

  • S == Structured

  • Q == Query

  • L == Language


    용어 정리

  • table == 표
    - row, record == 행
    - 데이터 하나하나, 데이터 자체
    - column == 열
    - 데이터의 구조를 나타냄


CREATE DATABASE opentutorials; #opentutorials라는 데이터베이스를 생성함

SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| music              |
| mysql              |
| opentutorials      | #여기에 있음!
| performance_schema |
| sys                |
+--------------------+

USE opentutorials; 

mysql> CREATE TABLE topic( #opentutorials에 topic 이라는 테이블을 생성함
    -> id INT(11) NOT NULL AUTO_INCREMENT, #NOT NULL == 빈 공간이 없어야함, AUTO_INCREMENT == 자동으로 증가함
    -> title VARCHAR(100) NOT NULL,
    -> description TEXT NULL, #NULL = 빈 공간을 허용함
    -> created DATETIME NOT NULL,
    -> author VARCHAR(30) NULL,
    -> profile VARCHAR(100) NULL
    -> , PRIMARY KEY(id)); #중요한 키 == id
DESC topic; #테이블의 구조를 보여줌
+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| id          | int          | 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    |                |
+-------------+--------------+------+-----+---------+----------------+
mysql> INSERT INTO topic (title,description,created,author,profile) VALUES('MySQL','MySQL is ...',NOW(),'egoing','developer');
mysql> SELECT * FROM topic; #creat한 것을 read하는 방법
+----+-------+--------------+---------------------+--------+-----------+
| id | title | description  | created             | author | profile   |
+----+-------+--------------+---------------------+--------+-----------+
|  1 | MySQL | MySQL is ... | 2021-08-27 20:46:55 | egoing | developer |
+----+-------+--------------+---------------------+--------+-----------+

mysql> INSERT INTO topic (title,description,created,author,profile) VALUES('ORACLE','Oracle is ...',NOW(),'egoing','developer');
mysql> INSERT INTO topic (title,description,created,author,profile) VALUES('SQL Server','SQL Server is ...',NOW(),'duru','database administrator');
mysql> INSERT INTO topic (title,description,created,author,profile) VALUES('PostgreSQL','PostgreSQL is ...',NOW(),'taeho','data scientist, developer');
mysql> INSERT INTO topic (title,description,created,author,profile) VALUES('MongoDB','MongoDB is ...',NOW(),'egoing','developer');

mysql> SELECT * FROM topic;
+----+------------+-------------------+---------------------+--------+---------------------------+
| id | title      | description       | created             | author | profile                   |
+----+------------+-------------------+---------------------+--------+---------------------------+
|  1 | MySQL      | MySQL is ...      | 2021-08-27 20:46:55 | egoing | developer                 |
|  2 | ORACLE     | Oracle is ...     | 2021-08-27 21:07:16 | egoing | developer                 |
|  3 | SQL Server | SQL Server is ... | 2021-08-27 21:13:50 | duru   | database administrator    |
|  4 | PostgreSQL | PostgreSQL is ... | 2021-08-27 21:15:49 | taeho  | data scientist, developer |
|  5 | MongoDB    | MongoDB is ...    | 2021-08-27 21:16:03 | egoing | developer                 |
+----+------------+-------------------+---------------------+--------+---------------------------+

좋은 웹페이지 즐겨찾기