REFERENCES 외래키 주기

2022. 3. 24. 14:29BackEnd

create sequence product_id_seq;
create sequence product_idx_seq;

create table product(
    id integer not null default nextval('product_id_seq'::regclass),
    idx integer not null default nextval('product_idx_seq'::regclass),
    company character varying(256) )REFERENCES companies ("company") on delete cascade COLLATE pg_catalog."default",
    title character varying(10485760) COLLATE pg_catalog."default",
    price double precision,
    couponCount integer,
    guidance character varying(10485760) COLLATE pg_catalog."default",
    category character varying(256) COLLATE pg_catalog."default",
    mainimg character varying(256) COLLATE pg_catalog."default",
    subimgs character varying(256) COLLATE pg_catalog."default",
    updatetime timestamp default current_timestamp,
    CONSTRAINT product_pkey PRIMARY KEY (id),
    CONSTRAINT product_unique UNIQUE (idx)
);
REFERENCES companies ("company") on delete cascade

On deletde cascade -> 자동으로 같이 지워주는 속성

 

'BackEnd' 카테고리의 다른 글

python datetime.datetime => convert datetime to string  (0) 2022.03.26
currenttime() - 현재시간 함수화  (0) 2022.03.25
2022-03-23(erc 셋팅 )  (0) 2022.03.24
env  (0) 2022.03.23
AWS S3에 파일 업로드하기  (0) 2022.03.23