본문 바로가기

Lecture

MariaDB Mysql table 생성

Default

database생성이 되어있어야 한다.

생성된 database가 선택이 되어있어야 한다.

 

CREATE TABLE [tablename](

[fieldname] [datatype],

[fieldname2] [datatype],

.

.

.

);

 

이렇게 하면 테이블과 그 안에 field까지 생성 된다.

만들어진 테이블은 desc [tablename]으로 확인

 

예시

MariaDB [(none)]> create database hello;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> use hello;
Database changed

MariaDB [hello]> CREATE TABLE board(
    -> idx int NOT NULL AUTO_INCREMENT PRIMARY KEY,
    -> subject varchar(100) NOT NULL,
    -> content text,
    -> today datetime NOT NULL,
    -> hit int
    -> );
Query OK, 0 rows affected (0.105 sec)

MariaDB [hello]> desc board;
+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| idx     | int(11)      | NO   | PRI | NULL    | auto_increment |
| subject | varchar(100) | NO   |     | NULL    |                |
| content | text         | YES  |     | NULL    |                |
| today   | datetime     | NO   |     | NULL    |                |
| hit     | int(11)      | YES  |     | NULL    |                |
+---------+--------------+------+-----+---------+----------------+
5 rows in set (0.040 sec)

field 5개를 가진 table이 완성되었다.

 

'Lecture' 카테고리의 다른 글

API사용 SERVER연결  (2) 2021.05.10
0422  (0) 2021.04.22
MariaDB - Database 확인, 생성, 삭제  (0) 2021.04.20
FORM tag  (0) 2021.04.20
query  (0) 2021.04.20