Database
[RDBMS]Postgres DB 주의사항 & 명령어 모음(1)
전봇대파괴자
2022. 2. 14. 23:22
주의사항
- postgres는 기본적으로 모든 이름을 소문자(lowercase)로 인식합니다. 만약 column명에 대문자가 포함되어 있다면 아래와 같이 쌍따옴표("")로 묶어주어야 합니다.
- 예시
# my_table이라는 이름의 테이블에 columnName이라는 column이 있다고 가정하겠습니다.
select columnName from my_table; # 실제로는 select columnname from my_table;로 인식됩니다.
select "columnName" from my_table; # 바르게 인식 # 작은 따옴표도 묶으면 안 됩니다!
postgres db 사용 시 유용하게 쓰일 수 있는 명령어들 & 주의사항입니다.
모든 데이터베이스 조회
\l
특정 데이터베이스 선택
\c "데이터베이스명"
선택한 데이터베이스의 모든 table 조회
\dt
table의 모든 column 정보 조회
\d + "table 명"
table 전체 데이터 조회
select*from "table 이름";
새로운 column 추가
alter table "table 이름" add "column 이름" "데이터 타입";
column 삭제
alter table "table 이름" drop "column 이름";
column 내 특정 값 바꾸기
update "table 이름" set "값을 수정할 column 이름"="바꿀 값" where "위치 조건";
column 명 바꾸기
alter table "table 이름" rename column "기존의 column 이름" to "새로 바꿀 column 이름";
table의 모든 데이터 삭제(롤백 불가)
truncate table "table 이름";
truncate table "table 이름" continue identity;
table의 모든 데이터 삭제 & index 초기화
truncate table "table 이름" restart identity;
table과 연결된 데이터까지 모두 삭제
truncate table "table 이름" cascade;