728x90
반응형
CREATE
1
2
3
4
5
6
7
8
|
CREATE TABLE TB_NAME(
COL_NAME1 VARCHAR(10) NOT NULL PRIMARY KEY,
COL_2NAME INT NOT NULL AUTO_INCREMENT UNIQUE,
COL_NAME3 CHAR(10) DEFAULT NULL,
COL_NAME4 VARCHAR(5) DEFAULT 'Y',
CONSTRAINT test_check CHECK(COL_NAME4 BETWEEN 'Y' AND 'N'),
PRIMARY KEY (COL_2NAME)
);
|
ALTER
1
2
3
4
5
6
7
8
9
|
ALTER TABLE TB_NAME ADD COL_NAME5 INT;
ALTER TABLE TB_NAME DROP COLUMN COL_NAME3;
ALTER TABLE TB_NAME MODIFY COL_NAME4 VARCHAR(3) DEFAULT 'N';
ALTER TABLE TB_NAME RENAME COLUMN COL_2NAME TO COL_NAME2;
ALTER TABLE TB_NAME ADD CONSTRAINT CONST_NAME1 PRIMARY KEY(COL_NAME4);
ALTER TABLE TB_NAME ADD CONSTRAINT CONST_NAME2 FOREIGN KEY(COL_NAME5) REFERENCES TB_NAME2(COL_NAME5);
ALTER TABLE TB_NAME ADD CONSTRAINT CONST_NAME3 CHECK (COL_NAME5 > 1);
ALTER TABLE TB_NAME ADD CONSTRAINT CONST_NAME4 CHECK (COL_NAME4 IN ('F','M'));
ALTER TABLE TB_NAME DROP CONSTRAINT CONST_NAME3;
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
DROP, RENAME, TRUNCATE
1
2
3
4
5
|
RENAME TB_NAME TO TB_NEW_NAME; -- 오라클
RENAME TABLE TB_NAME TO TB_NEW_NAME; -- MYSQL
TRUNCATE TABLE TB_NEW_NAME;
DROP TABLE TB_NEW_NAME;
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
728x90
반응형
'개발 > SQL' 카테고리의 다른 글
MYSQL #HY000Row 4611 was cut by GROUP_CONCAT() 에러 해결 방법 (0) | 2019.04.30 |
---|---|
오라클(MySQL) DML (SELECT, INSERT, UPDATE, DELETE) 총정리 (0) | 2019.04.14 |
MYSQL 중복되는 항목 찾기 (0) | 2019.03.27 |
MYSQL 순번 시퀀스 매기기 (그룹별 포함) (0) | 2019.03.21 |
MySQL 문자열 구분자 여러개 있을 때 여러 행으로 분리하기 (2) | 2019.03.07 |