Delete (SQL)

구조화 질의어(SQL)에서, DELETE 문은 테이블 또는 뷰에서 한개 이상의 행을 삭제한다. 하위 집합은 삭제에 대한 조건을 정의할 수 있으며, 정의하지 않으면 모든 행이 삭제된다.[1]

사용법

DELETE 문은 다음 구문을 따른다

DELETE FROM 테이블_또는_뷰_이름 [WHERE 조건]

WHERE 조건에 맞는 모든 행은 테이블에서 삭제된다. WHERE 절을 생략하면, 모든 행을 삭제한다.[2]DELETE문은 어떤 행이라도 리턴하지 않으며, 결과 집합을 발생시키지도 않는다.

DELETE 문을 실행하는 것은 다른 테이블을 삭제하게끔 실행하는 트리거가 발생할 수 있다. 예를 들면, 두 테이블이 외래 키로 연결되어 있고 행이 참조된 테이블에서 삭제된다면, 참조 무결성이 유지되도록 참조하고 있는 테이블에도 공통적으로 삭제된다.

예제

  • pies 테이블에서 flavor 열과 Lemon Meringue 열에서 행이 같으면 삭제한다:
DELETE FROM pies WHERE flavor='Lemon Meringue';
  • trees 테이블에서, height 값이 80보다 작으면 행을 삭제한다:
DELETE FROM trees WHERE height < 80;
  • mytable에서 모든 행을 삭제한다:
DELETE FROM mytable;
  • mytable에서 where 조건에 서브쿼리를 사용해 행을 삭제한다:
DELETE FROM mytable WHERE id IN (SELECT id FROM mytable2)
  • mytable에서 값 목록을 사용하여 행을 삭제한다:
DELETE FROM mytable WHERE id IN (value1, value2, value3, value4, value5)

각주

  1. “SQL Delete 문”. w3schools.com. 
  2. “DELETE(Transact-SQL) / SQL Server 2008 R2”. 2010년 11월 13일에 확인함. 

외부 링크

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.