-
connection & table 생성 <creat>DB/Oracle(DB) 2023. 7. 6. 14:36
CREATE TABLE coffee_menu (
no number GENERATED AS IDENTITY ,
coffee VARCHAR2(100) NOT NULL , /*VARCHAR2는 가변 길이를 의미(일반적으로 많이 씀)*/
kind VARCHAR2(100) NOT NULL ,
price number(11) DEFAULT 0 NOT NULL, /* 숫자타입 number */
reg_day date DEFAULT sysdate NOT NULL , /* 날짜타입 date */
mod_day date DEFAULT sysdate NOT NULL ,
CONSTRAINT pk_coffee_menu PRIMARY KEY(no)
)
;
COMMENT ON TABLE coffee_menu IS '커피/음료 메뉴';
-----------------------------------------------------
CREATE TABLE cust_info (
no number GENERATED AS IDENTITY ,
cust_id VARCHAR2(100) NOT NULL,
name VARCHAR2(100) NOT NULL,
email VARCHAR2(100) NOT NULL,
role VARCHAR2(100) DEFAULT 'MEMBER' NOT NULL , /* 권한 */
reg_day date default sysdate NOT NULL,
CONSTRAINT pk_cust_info PRIMARY KEY(no)
);
COMMENT ON TABLE cust_info IS '고객정보';
-- unique index 생성
ALTER TABLE cust_info ADD CONSTRAINT idx_cust_info UNIQUE(cust_id);
-----------------------------------------------------
CREATE TABLE order_list (
no number GENERATED AS IDENTITY ,
coffee_no number(11) NOT NULL,
coffee VARCHAR2(100) NOT NULL,
price number(11) NOT NULL,
cust_id VARCHAR2(100) NOT NULL,
name VARCHAR2(100) NOT NULL,
reg_day date default sysdate ,
CONSTRAINT pk_order_list PRIMARY KEY(no)
);
COMMENT ON TABLE order_list IS '주문내역';
-- foreign key 생성
ALTER TABLE order_list
ADD CONSTRAINT fk_coffee_no
FOREIGN KEY (coffee_no)
REFERENCES coffee_menu(no);
ALTER TABLE order_list
ADD CONSTRAINT fk_cust_id
FOREIGN KEY (cust_id) /*primary: 그 테이블의 주된키 FOREIGN KEY : 내 테이블에서 다른 테이블을 참조할때 사용 */
REFERENCES cust_info(cust_id);'DB > Oracle(DB)' 카테고리의 다른 글
SELECT - 단일테이블 <read> . feat:늦공김부장 (0) 2023.07.06 INSERT<creat> (0) 2023.07.06 user 생성<creat> (0) 2023.07.06 오라클 테스트 오류 :) (0) 2023.07.06 Connection Pool (0) 2023.06.30