"MySQL 테이블 생성 CREATE TABLE"의 두 판 사이의 차이

 
11번째 줄: 11번째 줄:
</source>
</source>


;실행결과
{{소스헤더|실행결과}}
<source lang='console'>
<source lang='console'>
mysql> CREATE TABLE dept (
mysql> CREATE TABLE dept (
44번째 줄: 44번째 줄:
);
);
</source>
</source>
;실행결과
 
{{소스헤더|실행결과}}
<source lang='console'>
<source lang='console'>
mysql> CREATE TABLE posts (  
mysql> CREATE TABLE posts (  

2019년 8월 21일 (수) 15:25 기준 최신판

MySQL CREATE TABLE
MySQL 테이블 생성

1 예시1: dept[ | ]

CREATE TABLE dept (
  dept_no INT(11) unsigned NOT NULL,
  dept_name VARCHAR(32) NOT NULL,
  PRIMARY KEY (dept_no)
);
실행결과
mysql> CREATE TABLE dept (
    ->   dept_no INT(11) unsigned NOT NULL,
    ->   dept_name VARCHAR(32) NOT NULL,
    ->   PRIMARY KEY (dept_no)
    -> );
Query OK, 0 rows affected (0.01 sec)
mysql> DESC dept;
+-----------+------------------+------+-----+---------+-------+
| Field     | Type             | Null | Key | Default | Extra |
+-----------+------------------+------+-----+---------+-------+
| dept_no   | int(11) unsigned | NO   | PRI | NULL    |       |
| dept_name | varchar(32)      | NO   |     | NULL    |       |
+-----------+------------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

2 예시2: posts[ | ]

CREATE TABLE posts ( 
  id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  subject varchar(255) NOT NULL,
  content mediumtext,
  created datetime,
  user_id int(10) unsigned NOT NULL,
  user_name varchar(32) NOT NULL,
  hit int(10) unsigned NOT NULL default '0',  
  PRIMARY KEY (id)
);
실행결과
mysql> CREATE TABLE posts ( 
    ->   id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    ->   subject varchar(255) NOT NULL,
    ->   content mediumtext,
    ->   created datetime,
    ->   user_id int(10) unsigned NOT NULL,
    ->   user_name varchar(32) NOT NULL,
    ->   hit int(10) unsigned NOT NULL default '0',  
    ->   PRIMARY KEY (id)
    -> );
Query OK, 0 rows affected (0.01 sec)
mysql> DESC posts;
+-----------+---------------------+------+-----+---------+----------------+
| Field     | Type                | Null | Key | Default | Extra          |
+-----------+---------------------+------+-----+---------+----------------+
| id        | bigint(20) unsigned | NO   | PRI | NULL    | auto_increment |
| subject   | varchar(255)        | NO   |     | NULL    |                |
| content   | mediumtext          | YES  |     | NULL    |                |
| created   | datetime            | YES  |     | NULL    |                |
| user_id   | int(10) unsigned    | NO   |     | NULL    |                |
| user_name | varchar(32)         | NO   |     | NULL    |                |
| hit       | int(10) unsigned    | NO   |     | 0       |                |
+-----------+---------------------+------+-----+---------+----------------+
7 rows in set (0.01 sec)

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}