[SQL] MySQL 테이블 생성, 제약조건(ON DELETE CASCADE)

1074 단어 mysqlmysql

MySQL CREATE

CREATE TABLE `T_COM_AUTH`(
  `AUTH_GROUP_SEQ` int(11)        NOT NULL AUTO_INCREMENT COMMENT '권한그룹번호', 
  `AUTH_GROUP_NM`  varchar(50)    NOT NULL COMMENT '권한그룹명', 
  `AUTH_GROUP_NM_EN`  varchar(50) DEFAULT NULL COMMENT '영문명', 
  `AUTH_CLASS_CD`  varchar(50)    DEFAULT NULL COMMENT '클래스코드', 
  `USE_AT`         char(1)        DEFAULT 'Y' COMMENT '사용여부', 
  `REGISTER_ID`      int(11)      NOT NULL COMMENT '등록인', 
  `REGIST_DT`      datetime       NOT NULL COMMENT '등록일', 
  `UPDATEER_ID`      int(11)      DEFAULT NULL COMMENT '수정인', 
  `UPDATE_DT`      datetime       COMMENT '수정일',
  PRIMARY KEY (`AUTH_GROUP_SEQ`)
) ENGINE=엔진명 DEFAULT CHARSET=utf8 COLLATE=utf8_latvian_ci COMMENT='권한';

MySQL FK제약조건 (ON DELETE CASCADE)

ALTER TABLE `T_COM_MENU_AUTH` ADD CONSTRAINT `fk_T_COM_MENU_AUTH_MENU_SEQ` FOREIGN KEY (
                        `MENU_SEQ`
)
            REFERENCES `T_COM_MENU` (
                        `MENU_SEQ`
)
ON DELETE CASCADE

좋은 웹페이지 즐겨찾기