728x90
CRUD
- Create, Read, Update, Delete
- Create, Read는 다 됨. Update, Delete는 안되는 경우도 있음
Read
SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| opentutorials |
| performance_schema |
| test |
+--------------------+
db 보여줌
SHOW TABLES IN opentutorials;
+-------------------------+
| Tables_in_opentutorials |
+-------------------------+
| topic |
+-------------------------+
opentutorials라는 db에 어떤 table이 있는지 보여줌
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 | |
+-------------+--------------+------+-----+---------+----------------+
DESC : describe
topic이라는 table의 description
INSERT INTO topic (title, description, created, author, profile) VALUES ('MySQL', 'MySQL is ...', NOW(), 'egoing', 'developer');
SELECT * FROM topic;
id는 auto_increment에 의해서 자동으로 입력되기 때문에 따로 지정 X
열 이름과 값 순서대로 입력
topic이라는 table에서(from) 전체(*)를 선택해서(select) 보여줌
반복해서 입력
완성
SELECT * FROM topic;
+----+------------+-------------------+---------------------+--------+---------------------------+
| id | title | description | created | author | profile |
+----+------------+-------------------+---------------------+--------+---------------------------+
| 1 | MySQL | MySQL is ... | 2022-04-17 19:27:40 | egoing | developer |
| 2 | ORACLEL | ORACLEL is ... | 2022-04-17 19:29:30 | egoing | developer |
| 3 | SQL Server | SQL Server is ... | 2022-04-17 19:43:49 | duru | data administrator |
| 4 | PostgreSQL | PostgreSQL is ... | 2022-04-17 19:44:56 | taeho | data scientist, developer |
| 5 | MongoDB | MongoDB is ... | 2022-04-17 19:45:47 | egoing | developer |
+----+------------+-------------------+---------------------+--------+---------------------------+
No database selected 에러
USE opentutorials;
728x90
'Language > MySQL' 카테고리의 다른 글
[생활코딩] 4일차 - 4. JOIN (0) | 2022.04.24 |
---|---|
[생활코딩] 3일차 - 3. CRUD : Update, Delete (0) | 2022.04.17 |
[생활코딩] 3일차 - 2. CRUD : Read (0) | 2022.04.17 |
[생활코딩] 2일차. 테이블 생성 (0) | 2022.04.09 |
[생활코딩] 1일차. 실행 및 서버 접속, 스키마 사용 생성 (0) | 2022.04.09 |