[PostGreSQL] DO~BEGIN~END 사용 예시

식빵·2023년 3월 31일
0

postgresql-memo

목록 보기
8/34
DO
$$
BEGIN
    drop table if exists coding_toast.user_test;
    create table coding_toast.user_test
    (
        id    int,
        attr1 character varying(20),
        attr2 character varying(20),
        attr3 character varying(20),
        attr4 character varying(20)
    );

    alter table coding_toast.user_test
        add constraint pk_for_coding_toast PRIMARY KEY (id);

    insert into coding_toast.user_test(id, attr1, attr2, attr3, attr4)
    values (1,2,3,4,5),
           (2,2,3,4,5),
           (3,2,3,4,5),
           (4,2,3,4,5),
           (5,2,3,4,5),
           (6,2,3,4,5),
           (7,2,3,4,5),
           (8,2,3,4,5);
END
$$
profile
백엔드를 계속 배우고 있는 개발자입니다 😊

0개의 댓글