• Home
  • About
    • Che1's Blog photo

      Che1's Blog

      Che1's Dev Blog

    • Learn More
    • Facebook
    • Instagram
    • Github
    • Steam
    • Youtube
  • Posts
    • All Posts
    • Django
    • Python
    • Front-end
    • Algorithm
    • etc
    • All Tags
  • Projects

[SQL] DELETE

07 Oct 2017

Reading time ~1 minute

예제 테이블

Customers
CustomerID CustomerName ContactName Address City PostalCode Country
1 Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 12209 Germany
2 Ana Trujillo Emparedados y helados Ana Trujillo Avda. de la Constitución 2222 México D.F. 05021 Mexico
3 Antonio Moreno Taquería Antonio Moreno Mataderos 2312 México D.F. 05023 Mexico
4 Around the Horn Thomas Hardy 120 Hanover Sq. London WA1 1DP UK
5 Berglunds snabbköp Christina Berglun Berguvsvägen 8 Luleå S-958 22 Sweden

DELETE 는 테이블에서 특정 레코드를 삭제할 때 사용한다.

DELETE FROM 테이블이름
WHERE 조건;

UPDATE 와 마찬가지로 WHERE 절의 조건이 어떤 레코드를 삭제할지 결정한다. WHERE 절이 누락되면 테이블의 모든 레코드를 삭제한다.

아래 명령은 Customers 테이블에서 CustomerName 필드의 값이 Alfreds Futterkiste 인 레코드를 삭제한다.

DELETE FROM Customers
WHERE CustomerName='Alfreds Futterkiste';

모든 레코드들을 조회해보면 아래와 같다.


Result
CustomerID CustomerName ContactName Address City PostalCode Country
2 Ana Trujillo Emparedados y helados Ana Trujillo Avda. de la Constitución 2222 México D.F. 05021 Mexico
3 Antonio Moreno Taquería Antonio Moreno Mataderos 2312 México D.F. 05023 Mexico
4 Around the Horn Thomas Hardy 120 Hanover Sq. London WA1 1DP UK
5 Berglunds snabbköp Christina Berglund Berguvsvägen 8 Luleå S-958 22 Sweden
6 Cardinal null null null 4006 Norway

아래의 두 명령은 테이블 내의 모든 레코드들을 삭제한다. 이 때, 테이블의 구조, 속성 등은 그대로 남는다.

DELETE FROM table_name;
DELETE * FROM table_name;

위로


SQL 목차
  • [SQL] JOIN, UNION
  • [SQL] DELETE
  • [SQL] UPDATE
  • [SQL] INSERT INTO
  • [SQL] SELECT를 꾸며주는 옵션 모음
  • [SQL] WHERE
  • [SQL] SELECT
  • [SQL] SQL 이란?

Reference

W3School: https://www.w3schools.com/sql/



SQL Share Tweet +1