> For the complete documentation index, see [llms.txt](https://dahye-jeong.gitbook.io/database/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dahye-jeong.gitbook.io/database/mysql/2019-03-16-table.md).

# MySQL Table

## SQL

Structured(구조화되어있다.) Query(데이터베이스에 질의한다.) Language의 약자이다.

* 압도적인 데이터베이스 시스템이 SQL로 작동되고 있다.

## 테이블 구조

![](http://cfile22.uf.tistory.com/original/17385D474D71A69C269849)

## 실습하기

### 테이블 생성하기

![](http://www.sqltutorial.org/wp-content/uploads/2016/04/SQL-Cheat-Sheet-2.png)

[데이터 타입 보기](https://www.techonthenet.com/mysql/datatypes.php)

```
mysql> CREATE TABLE topic(
    -> id INT(11) NOT NULL AUTO_INCREMENT,
    -> title VARCHAR(100) NOT NULL,
    -> description TEXT NULL,
    -> created_at DATETIME NOT NULL,
    -> author VARCHAR(30) NULL,
    -> profile VARCHAR(100) NULL,
    -> PRIMARY KEY(id));
Query OK, 0 rows affected (0.11 sec)
```

* NOT NULL : 공백은 허용하지 않는다.
* AUTO\_INCREMENT : 자동으로 한개씩 증가한다.
* PRIMARY KEY : 중복이 되지 않는 값, 식별자

### 테이블 보기

```
mysql> SHOW TABLES;
+-------------------------+
| Tables_in_opentutorials |
+-------------------------+
| topic                   |
+-------------------------+
1 row in set (0.01 sec)
```

### 테이블 구조 보기

```
mysql> 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_at  | datetime     | NO   |     | NULL    |                |
| author      | varchar(30)  | YES  |     | NULL    |                |
| profile     | varchar(100) | YES  |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+
6 rows in set (0.01 sec)
```
