본문 바로가기
Database/MariaDB

[MariaDB; 마리아디비] 마리아DB 주석처리

by daddydontsleep 2024. 1. 2.
728x90
728x90

MariaDB Logo

오늘은 간단한 팁하나 남기고 가겠습니다.

쿼리문을 작성하다보면 주석처리를 해야할때가 가끔 생깁니다.

그럴때를 위해 글을 남깁니다.

마리아DB 주석처리

마리아DB에서 주석 처리하는 방법은 여러 가지가 있습니다. 주석은 SQL 쿼리나 데이터베이스 객체 (테이블, 컬럼 등)에 대한 설명이나 메모를 추가할 때 사용됩니다. 아래는 주석 처리 방법의 몇 가지 예제입니다.

  1. 한 줄 주석 처리
    --
    이렇게 두 개의 대시 기호(하이픈)로 시작하면 해당 줄의 나머지 부분이 주석 처리됩니다.
    -- 한 줄 주석 처리​
  2. 블록 주석 처리
    /* */
    /* 이렇게 시작하고 */ 이렇게 끝나는 블록 주석은 여러 줄에 걸쳐 사용할 수 있습니다. 주석 처리할 부분을 모두 포함하도록 시작과 끝을 명시해야 합니다.
    /* 여러 줄 주석 처리
    블록 주석 처리
    안녕하세요. Tistory 블로그입니다.
    https://daddydontsleep.tistory.com/
    마지막은 이렇게
    */
  3. 주석 처리된 테이블 생성문
    create or replace table api_db.users
    (
        id              bigint auto_increment comment '식별자'
            primary key,
        address         varchar(255)                          not null comment '주소',
        authorities     varchar(32)                           not null comment '권한 설정 - ROLE_USER:사용자 / ROLE_ADMIN:관리자 / ROLE_SUPER:최고 관리자',
        email           varchar(255)                          not null comment '이메일',
        is_withdrawn    varchar(1)                            not null comment '탈퇴 여부',
        last_login_time timestamp default current_timestamp() not null on update current_timestamp() comment '최근 로그인 시간',
        -- name 에 대한 설명을 주석을 통해 작성할 수 있습니다.
        name            varchar(255)                          not null comment '사용자 이름',
        password        varchar(255)                          not null comment '비밀번호',
        phone_number    varchar(255)                          not null comment '핸드폰 번호',
        username        varchar(255)                          not null comment '아이디',
        withdrawn_time  datetime(6)                           null comment '탈퇴 날짜',
        constraint UK_6dotkott2kjsp8vw4d0m25fb7
            unique (email),
        constraint UK_r43af9ap4edm43mmtq01oddj6
            unique (username)
    );​
  4. 주석 처리된 SQL 쿼리문
    select *
    from users
    where 1 = 1
    -- and (name like '%a%' or name like '%b%')​

    특정 조건문을 주석처리하여 원하는 결과값을 찾거나 잘못된 조건문을 찾기위해서 주석처리를 하기도 합니다.

 

p.s 주석은 실행되지 않으므로 데이터베이스 작업에는 영향을 주지 않습니다.

끝.

 

728x90
300x250