
CREATE TABLE TB_MENU
(
	MENU_ID              VARCHAR2(20) NOT NULL ,
	NM                   VARCHAR2(100) NOT NULL ,
	URL                  VARCHAR2(200) NULL ,
	MENU_LEVEL           NUMBER NULL ,
	USE_AT               CHAR(1) NOT NULL ,
	HIDE_AT              CHAR(1) DEFAULT  'N'  NOT NULL,
	PARNTS_MENU_ID       VARCHAR2(20) NULL ,
	DC                   VARCHAR2(200) NULL ,
	SORT_ORDR            NUMBER NOT NULL ,
	MENU_AT              CHAR(1) DEFAULT  'M'  NOT NULL,
	CREAT_DT             DATE DEFAULT SYSDATE NOT NULL ,
	CRTR                 VARCHAR2(100) NOT NULL ,
	UPDT_DT              DATE DEFAULT SYSDATE NOT NULL ,
	UPDUSR               VARCHAR2(100) NOT NULL
);

CREATE UNIQUE INDEX XPKTB_MENU ON TB_MENU
(MENU_ID   ASC);

ALTER TABLE TB_MENU
	ADD CONSTRAINT  XPKTB_MENU PRIMARY KEY (MENU_ID);

CREATE TABLE TB_MENU_AUTHOR
(
	MENU_ID              VARCHAR2(20) NOT NULL ,
	GROUP_ID             VARCHAR2(10) NOT NULL ,
	CRTFC_AT             CHAR(1) DEFAULT  'N'  NOT NULL,
	CRTR                 VARCHAR2(100) NOT NULL ,
	UPDT_DT              DATE DEFAULT SYSDATE NOT NULL ,
	UPDUSR               VARCHAR2(100) NOT NULL ,
	CREAT_DT             DATE DEFAULT SYSDATE NOT NULL
);

CREATE UNIQUE INDEX XPKTB_MENU_AUTHOR ON TB_MENU_AUTHOR
(MENU_ID   ASC,GROUP_ID   ASC);

ALTER TABLE TB_MENU_AUTHOR
	ADD CONSTRAINT  XPKTB_MENU_AUTHOR PRIMARY KEY (MENU_ID,GROUP_ID);

CREATE TABLE TB_MENU_AUTHOR_GROUP
(
	GROUP_ID             VARCHAR2(10) NOT NULL ,
	NM                   VARCHAR2(100) NOT NULL ,
	DC                   VARCHAR2(200) NULL ,
	USE_AT               CHAR(1) NOT NULL ,
	SORT_ORDR            NUMBER NOT NULL ,
	UPDT_DT              DATE DEFAULT SYSDATE NOT NULL ,
	UPDUSR               VARCHAR2(100) NOT NULL ,
	CREAT_DT             DATE DEFAULT SYSDATE NOT NULL ,
	CRTR                 VARCHAR2(100) NOT NULL
);

CREATE UNIQUE INDEX XPKTB_MENU_AUTHOR_GROUP ON TB_MENU_AUTHOR_GROUP
(GROUP_ID   ASC);

ALTER TABLE TB_MENU_AUTHOR_GROUP
	ADD CONSTRAINT  XPKTB_MENU_AUTHOR_GROUP PRIMARY KEY (GROUP_ID);

CREATE TABLE TB_USER_AUTHOR_MAPNG
(
	GROUP_ID             VARCHAR2(10) NOT NULL,
	USER_ID              VARCHAR2(20) NOT NULL,
	CREAT_DT             DATE DEFAULT SYSDATE NOT NULL ,
	CRTR                 VARCHAR2(100) NOT NULL ,
	UPDT_DT              DATE DEFAULT SYSDATE NOT NULL ,
	UPDUSR               VARCHAR2(100) NOT NULL
);

CREATE UNIQUE INDEX XPKTB_USER_AUTHOR_MAPNG ON TB_USER_AUTHOR_MAPNG
(GROUP_ID   ASC,USER_ID   ASC);

ALTER TABLE TB_USER_AUTHOR_MAPNG
	ADD CONSTRAINT  XPKTB_USER_AUTHOR_MAPNG PRIMARY KEY (GROUP_ID,USER_ID);

ALTER TABLE TB_MENU_AUTHOR
	ADD (CONSTRAINT R_5 FOREIGN KEY (MENU_ID) REFERENCES TB_MENU (MENU_ID));

ALTER TABLE TB_MENU_AUTHOR
	ADD (CONSTRAINT R_10 FOREIGN KEY (GROUP_ID) REFERENCES TB_MENU_AUTHOR_GROUP (GROUP_ID));

ALTER TABLE TB_USER_AUTHOR_MAPNG
	ADD (CONSTRAINT R_11 FOREIGN KEY (GROUP_ID) REFERENCES TB_MENU_AUTHOR_GROUP (GROUP_ID));

ALTER TABLE TB_USER_AUTHOR_MAPNG
	ADD (CONSTRAINT R_12 FOREIGN KEY (USER_ID) REFERENCES TB_USER (USER_ID));


