FastAPI SQL Queries Introduction - 35

2022. 12. 30. 23:23·Develop/FastAPI
728x90
SMALL
sql 쿼리 구문에 대한 간략한 소개
32번 페이지에서 만든 테이블로 조작

 

1. select

#todos의 테이블 전체 열과 행을 조회한다.

SELECT * FROME todos;
#todos의 특정컬럼을 조회한다.
#컬럼을 적은 순서대로 컬럼이 조회되서 나온다.

SELECT title FROM todos;
SELECT description FROM todos;
SELECT title, description FROM todos;
SELECT title, description, priority FROM todos;
#todos의 특정값에 해당하는 데이터를 조회한다.
#priority열의 값이 5인 행만 조회한다.
#title열의 값이 Feed dog인 행만 조회한다.
#id열의 값이 2인 행만 조회한다.

SELECT * FROM todos WHERE priority=5;
SELECT * FROM todos WHERE title='Feed dog';
SELECT * FROM todos WHERE id=2;

 

2. insert

#todos테이블에 열 title, description, priority, complete에 
#순서대로 값 'Go to store', 'To pick up eggs', 4, False 삽입한다.

INSERT INTO todos (title, description, priority, complete)
VALUES ('Go to store', 'To pick up eggs', 4, False);

 

3. update

#특정 값에 해당하는 데이터의 값을 변경한다.
#id열의 값이 5인 데이터들의 complete열의 값을 True로 변경한다.
#title열의 값이 Learn Something new인 데이터들의 complete열의 값을 True로 변경한다.


UPDATE todos SET complete=True WHERE id=5;
UPDATE todos SET complete=True WHERE title='Learn something new';

 

4. delete

#특정 값에 해당하는 데이터의를 삭제한다.
#id열의 값이 5인 데이터를 삭제한다.
#complete열의 값이 0인 모든 데이터를 삭제한다.

DELETE FROM todos WHERE id = 5;
DELETE FROM todos WHERE complete = 0;
728x90
SMALL
저작자표시 비영리 변경금지 (새창열림)

'Develop > FastAPI' 카테고리의 다른 글

FastAPI SessionLocal을 통한 테이블 읽기 - 37  (0) 2022.12.31
FastAPI SQLite3 Setting Up Todos - 36  (0) 2022.12.30
FastAPI Installation of SQLite3 Terminal (Mac) - 34  (0) 2022.12.30
FastAPI Installation of SQLite3 Terminal (Windows) - 34  (0) 2022.12.30
FastAPI Create Database Connection for API(Sqlite) - 33  (0) 2022.12.30
'Develop/FastAPI' 카테고리의 다른 글
  • FastAPI SessionLocal을 통한 테이블 읽기 - 37
  • FastAPI SQLite3 Setting Up Todos - 36
  • FastAPI Installation of SQLite3 Terminal (Mac) - 34
  • FastAPI Installation of SQLite3 Terminal (Windows) - 34
동석해요
동석해요
공부하고 싶은게 많은, 사소한 IT 지식들 공유
    250x250
  • 동석해요
    개발로 자기계발
    동석해요
  • 전체
    오늘
    어제
    • 분류 전체보기 (226)
      • Develop (126)
        • 기초지식 (12)
        • FastAPI (102)
        • Django (11)
      • Database & Data (62)
        • 기초지식 (16)
        • MySQL (29)
        • PostgreSQL (8)
        • 데이터 분석 (9)
      • 인공지능 (11)
        • PyTorch (9)
      • Cloud (8)
        • AWS (4)
        • GCP (2)
      • 버그처리 (14)
      • 회고 & 일상 (5)
  • 인기 글

  • 최근 글

  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.3
동석해요
FastAPI SQL Queries Introduction - 35
상단으로

티스토리툴바