mysql>CREATE DATABASE 데이터베이스이름 default CHARACTER SET UTF8;
mysql>show databases;
mysql>use 데이터베이스이름;
mysql>drop database 데이터베이스이름;
mysql> ALTER DATABASE 데이터베이스이름
DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci;
mysql> show tables;
mysql> CREATE TABLE todo (
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
name VARCHAR(100) NOT NULL,
sequence INT(1) NOT NULL,
type VARCHAR(20) DEFAULT 'TODO',
regdate DATETIME DEFAULT NOW(),
PRIMARY KEY (id)
);
mysql> desc todo;
+----------+-----------------+------+-----+------------+---------+
| Field | Type | Null | Key | Default | Extra |
+----------+-----------------+------+-----+------------+---------+
| id | bigint unsigned | NO | PRI | NULL | auto_increment|
| title | varchar(255) | NO | | NULL | |
| name | varchar(100) | NO | | NULL | |
| sequence | int | NO | | NULL | |
| type | varchar(20) | YES | | TODO | |
| regdate | datetime | YES | | CURRENT_TIMESTAMP | DEFAULT_GENERATED |
+----------+-----------------+------+-----+------------+---------+
6 rows in set (0.02 sec)
mysql> SELECT * FROM todo;
mysql> INSERT into todo (title, name, sequence) values ("sql공부", "yong", "1");
mysql> UPDATE todo SET type = "DOING" WHERE id = 1;
mysql> UPDATE todo
SET type = CASE
WHEN type = TODO THEN DOING
WHEN type = DOING THEN DONE
ELSE DONE
END
WHERE id = 1;
mysql> ALTER TABLE table_name ADD COLUMN ex_column varchar(32) NOT NULL;
mysql> ALTER TABLE table_name MODIFY COLUMN ex_column varchar(16) NULL;
mysql> ALTER TABLE table_name CHANGE COLUMN ex_column ex_column2 varchar(16) NULL;
mysql> ALTER TABLE table_name DROP COLUMN ex_column; //컬럼 삭제 (Drop)
mysql> ALTER TABLE table_name1 RENAME table_name2; //테이블 이름 변경 (RENAME)
출처 :: https://velog.io/@ryong9rrr/mySQL-%EA%B8%B0%EB%B3%B8-%EC%82%AC%EC%9A%A9%EB%B2%95-%EC%A0%95%EB%A6%AC%EC%98%88%EC%A0%9C
https://extbrain.tistory.com/39