티스토리 뷰

IA/DB

[mysql] 실습 schema 및 object 생성

kiostory 2019. 3. 1. 13:28

현재 스키마들

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| employees          |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

실습 schema 생성

mysql> create schema shopdb;
Query OK, 1 row affected (1.34 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| employees          |
| mysql              |
| performance_schema |
| shopdb             |
| sys                |
+--------------------+


mysql> use shopdb;
Database changed


실습 테이블 생성


mysql> create table membertbl(
    -> memberid char(8) not null,
    -> membername char(5) not null,
    -> memberaddress char(20),
    -> primary key(memberid)
    -> );

Query OK, 0 rows affected (0.01 sec)


mysql> show tables;
+------------------+
| Tables_in_shopdb |
+------------------+
| membertbl        |
+------------------+
1 row in set (0.00 sec)


mysql> desc membertbl;
+---------------+----------+------+-----+---------+-------+
| Field         | Type     | Null | Key | Default | Extra |
+---------------+----------+------+-----+---------+-------+
| memberid      | char(8)  | NO   | PRI | NULL    |       |
| membername    | char(5)  | NO   |     | NULL    |       |
| memberaddress | char(20) | YES  |     | NULL    |       |
+---------------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> create table producttbl (
    -> productname char(4) not null,
    -> cost int not null,
    -> makedate date null,
    -> company char(5) null,
    -> amount int not null,
    -> primary key(productname)
    -> );

Query OK, 0 rows affected (0.01 sec)


mysql> show tables;
+------------------+
| Tables_in_shopdb |
+------------------+
| membertbl        |
| producttbl       |
+------------------+
2 rows in set (0.00 sec)


mysql> desc producttbl;
+-------------+---------+------+-----+---------+-------+
| Field       | Type    | Null | Key | Default | Extra |
+-------------+---------+------+-----+---------+-------+
| productname | char(4) | NO   | PRI | NULL    |       |
| cost        | int(11) | NO   |     | NULL    |       |
| makedate    | date    | YES  |     | NULL    |       |
| company     | char(5) | YES  |     | NULL    |       |
| amount      | int(11) | NO   |     | NULL    |       |
+-------------+---------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql>


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함